runcc 0.1.2 → 0.1.4
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/.claude/skills/publish/SKILL.md +156 -0
- package/CHANGELOG.md +19 -1
- package/CLAUDE.md +121 -105
- package/README.md +31 -31
- package/dist/index.js +22 -16
- package/package.json +1 -1
- package/.claude/skills/npm-publish/SKILL.md +0 -209
- package/PLAN.md +0 -236
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: publish
|
|
3
|
+
description: 自动化 npm 包发布准备工作流。预检查 → 询问版本 → npm version → 测试 → 构建 → CHANGELOG → 提交 → 推送 → 打印发布命令(用户手动执行 npm publish)。触发词:发布新版本/publish to npm/bump version/release。
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# NPM 发布工作流
|
|
7
|
+
|
|
8
|
+
预检查 → 提交未保存更改 → 询问版本 → npm version → 测试 → 构建 → CHANGELOG → 提交 → 推送 → 打印发布命令
|
|
9
|
+
|
|
10
|
+
## 工作流程
|
|
11
|
+
|
|
12
|
+
### 0. 预检查(重要!)
|
|
13
|
+
|
|
14
|
+
在开始任何操作前,**必须先检查 git 状态**:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
# 检查当前分支
|
|
18
|
+
git branch --show-current
|
|
19
|
+
|
|
20
|
+
# 检查工作区状态
|
|
21
|
+
git status --short
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
**如果工作区干净**:直接进入步骤 1。
|
|
25
|
+
|
|
26
|
+
**如果有未提交更改**:使用 `AskUserQuestion` 询问用户:
|
|
27
|
+
- 先提交更改(**必须使用 `/commit-commands:commit` skill**)
|
|
28
|
+
- 丢弃更改(`git restore .`)
|
|
29
|
+
- 中止流程
|
|
30
|
+
|
|
31
|
+
**关键原因**:`npm version` 命令要求工作目录必须是干净状态,否则会报错退出。
|
|
32
|
+
|
|
33
|
+
### 1. 询问目标版本
|
|
34
|
+
|
|
35
|
+
使用 `AskUserQuestion` 询问用户要升级到什么版本:
|
|
36
|
+
|
|
37
|
+
| 类型 | 说明 | 示例 |
|
|
38
|
+
|------|------|------|
|
|
39
|
+
| patch | 错误修复、小改动 | 1.0.0 → 1.0.1 |
|
|
40
|
+
| minor | 新功能、向后兼容 | 1.0.0 → 1.1.0 |
|
|
41
|
+
| major | 破坏性更改 | 1.0.0 → 2.0.0 |
|
|
42
|
+
| custom | 指定确切版本号 | 1.0.0 → 1.2.3 |
|
|
43
|
+
|
|
44
|
+
### 2. 修改 npm 版本
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
npm version <patch|minor|major|x.y.z>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
此命令会:
|
|
51
|
+
- 更新 package.json 和 package-lock.json 版本号
|
|
52
|
+
- 创建 git 提交(消息格式:`v<x.y.z>`)
|
|
53
|
+
- 创建 git 标签(`v<x.y.z>`)
|
|
54
|
+
|
|
55
|
+
### 3. 运行测试
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
bun run test
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
- 如果 package.json 有 test 脚本,执行测试
|
|
62
|
+
- 测试失败则中止流程,提示用户修复
|
|
63
|
+
- 无 test 脚本则跳过
|
|
64
|
+
|
|
65
|
+
### 4. 打包编译
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
bun run build
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
- 如果 package.json 有 build 脚本,执行构建
|
|
72
|
+
- 构建失败则中止流程,提示用户修复
|
|
73
|
+
- 无 build 脚本则跳过
|
|
74
|
+
|
|
75
|
+
### 5. 创建 CHANGELOG
|
|
76
|
+
|
|
77
|
+
#### 存在 CHANGELOG.md 时
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
# 查看自上次发布的提交
|
|
81
|
+
git log $(git tag -l | tail -n 1)..HEAD --oneline
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
**生成条目**:
|
|
85
|
+
- 格式:`## [<版本号>] - YYYY-MM-DD`
|
|
86
|
+
- 按类型分组:新功能、错误修复、破坏性更改
|
|
87
|
+
|
|
88
|
+
**审核流程**:
|
|
89
|
+
1. 显示生成的变更日志
|
|
90
|
+
2. 使用 `AskUserQuestion` 确认或修改
|
|
91
|
+
3. 更新 CHANGELOG.md
|
|
92
|
+
|
|
93
|
+
#### 不存在 CHANGELOG.md 时
|
|
94
|
+
|
|
95
|
+
询问用户是否创建。
|
|
96
|
+
|
|
97
|
+
### 6. 提交 git
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
git add CHANGELOG.md
|
|
101
|
+
git commit -m "docs: update CHANGELOG for <版本号>"
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### 7. 询问是否 git push
|
|
105
|
+
|
|
106
|
+
使用 `AskUserQuestion` 询问是否推送:
|
|
107
|
+
|
|
108
|
+
```
|
|
109
|
+
是否推送到远程仓库?
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
用户确认后执行:
|
|
113
|
+
```bash
|
|
114
|
+
git push && git push --tags
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### 8. 打印 npm publish 命令
|
|
118
|
+
|
|
119
|
+
显示发布命令,要求用户复制手动执行:
|
|
120
|
+
|
|
121
|
+
```
|
|
122
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
123
|
+
📦 准备发布: <package-name>@<new-version>
|
|
124
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
125
|
+
|
|
126
|
+
请复制以下命令并执行:
|
|
127
|
+
|
|
128
|
+
npm publish
|
|
129
|
+
|
|
130
|
+
(如需公共作用域包,使用: npm publish --access public)
|
|
131
|
+
|
|
132
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### 发布摘要
|
|
136
|
+
|
|
137
|
+
```
|
|
138
|
+
✅ 准备工作完成
|
|
139
|
+
|
|
140
|
+
- 包名: <package-name>
|
|
141
|
+
- 新版本: <new-version>
|
|
142
|
+
- Git 标签: v<new-version>
|
|
143
|
+
- CHANGELOG: 已更新
|
|
144
|
+
|
|
145
|
+
请执行上方 npm publish 命令完成发布。
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## 最佳实践
|
|
149
|
+
|
|
150
|
+
- 发布前运行测试
|
|
151
|
+
- 保持 CHANGELOG.md 最新
|
|
152
|
+
- 遵循语义化版本规范
|
|
153
|
+
- 确认前审查更改
|
|
154
|
+
- 始终先提交再发布
|
|
155
|
+
- 为发布打标签
|
|
156
|
+
- 清楚标注破坏性更改
|
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,24 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.1.4] - 2026-01-19
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Support `runcc -- <args>` syntax for directly launching official Claude mode with argument passthrough
|
|
12
|
+
- This provides a more concise way to launch official Claude when no provider is needed
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
- Updated usage examples in error messages to include the new `runcc -- <args>` syntax
|
|
16
|
+
- Enhanced publish skill with better pre-check workflow documentation
|
|
17
|
+
- Reorganized CLAUDE.md with clearer structure
|
|
18
|
+
|
|
19
|
+
## [0.1.3] - 2026-01-19
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
- Renamed `npm-publish` skill to `publish` for consistency
|
|
23
|
+
- Removed deprecated `PLAN.md` file
|
|
24
|
+
- Updated project documentation and test files
|
|
25
|
+
|
|
8
26
|
## [0.1.2] - 2026-01-19
|
|
9
27
|
|
|
10
28
|
### Changed
|
|
@@ -23,5 +41,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
23
41
|
- Support for official Claude API and third-party providers (GLM, DeepSeek, Minimax)
|
|
24
42
|
- Custom endpoint management (add/remove)
|
|
25
43
|
- Proxy configuration support
|
|
26
|
-
- Configuration persistence in `~/.
|
|
44
|
+
- Configuration persistence in `~/.runcc/config.json`
|
|
27
45
|
- Integration with Claude CLI settings (`~/.claude/settings.json`)
|
package/CLAUDE.md
CHANGED
|
@@ -4,146 +4,162 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
|
|
|
4
4
|
|
|
5
5
|
## 项目概述
|
|
6
6
|
|
|
7
|
-
**
|
|
7
|
+
**runcc** 是一个 TypeScript CLI 工具,用于在 Claude Code 中切换不同的 API 端点。它允许用户使用第三方 API 提供商(GLM、DeepSeek、Minimax)或自定义端点,同时保持与 Claude 原生配置的无缝集成。
|
|
8
8
|
|
|
9
9
|
## 开发命令
|
|
10
10
|
|
|
11
|
+
### 运行与构建
|
|
11
12
|
```bash
|
|
12
|
-
#
|
|
13
|
-
bun
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
bun run dev
|
|
17
|
-
|
|
18
|
-
# 构建输出到 dist/index.js
|
|
19
|
-
bun run build
|
|
20
|
-
|
|
21
|
-
# 构建独立二进制可执行文件
|
|
22
|
-
bun run build:bin
|
|
23
|
-
|
|
24
|
-
# 全局安装(本地测试)
|
|
25
|
-
bun install -g .
|
|
13
|
+
bun run dev # 开发模式运行
|
|
14
|
+
bun run build # 编译到 dist/
|
|
15
|
+
bun run build:bin # 编译独立二进制文件
|
|
16
|
+
```
|
|
26
17
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
bun test
|
|
18
|
+
### 测试
|
|
19
|
+
```bash
|
|
20
|
+
bun test # 运行所有测试
|
|
21
|
+
bun test --watch # 监视模式
|
|
22
|
+
bun run test:unit # 仅单元测试
|
|
23
|
+
bun run test:integration # 仅集成测试
|
|
30
24
|
```
|
|
31
25
|
|
|
32
|
-
|
|
26
|
+
### 发布
|
|
27
|
+
```bash
|
|
28
|
+
/publish # 使用 publish skill 自动化发布流程
|
|
29
|
+
```
|
|
33
30
|
|
|
34
31
|
## 核心架构
|
|
35
32
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
```
|
|
33
|
+
### 双配置系统
|
|
34
|
+
|
|
35
|
+
1. **RunCC Config** (`~/.runcc/config.json`)
|
|
36
|
+
- 存储自定义端点、API token、代理设置
|
|
37
|
+
- 通过 `src/config/storage.ts` 管理
|
|
38
|
+
- 结构示例:
|
|
39
|
+
```json
|
|
40
|
+
{
|
|
41
|
+
"endpoints": [...],
|
|
42
|
+
"tokens": {"glm": "sk-...", "deepseek": "sk-..."},
|
|
43
|
+
"lastUsed": "glm",
|
|
44
|
+
"proxy": {"enabled": true, "url": "http://...", "clearForOfficial": false}
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
2. **Claude Settings** (`~/.claude/settings.json`)
|
|
49
|
+
- Claude 原生配置文件
|
|
50
|
+
- 通过 `src/utils/claude-settings.ts` 管理
|
|
51
|
+
- 包含 proxy、apiUrl、anthropicApiKey 和 env 配置
|
|
52
|
+
- 结构示例:
|
|
53
|
+
```json
|
|
54
|
+
{
|
|
55
|
+
"proxy": "http://...",
|
|
56
|
+
"apiUrl": "https://...",
|
|
57
|
+
"anthropicApiKey": "sk-...",
|
|
58
|
+
"env": {
|
|
59
|
+
"ANTHROPIC_BASE_URL": "...",
|
|
60
|
+
"ANTHROPIC_AUTH_TOKEN": "..."
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
**关键设计模式:临时修改模式** - 在官方模式下启动时,临时清除第三方配置并在 Claude 退出后恢复。
|
|
50
66
|
|
|
51
67
|
### 目录结构
|
|
52
68
|
|
|
53
69
|
```
|
|
54
70
|
src/
|
|
55
|
-
├── index.ts # CLI
|
|
56
|
-
├── commands/ #
|
|
57
|
-
│ ├── run.ts #
|
|
58
|
-
│ ├──
|
|
59
|
-
│ ├──
|
|
60
|
-
│ ├──
|
|
61
|
-
│ └──
|
|
62
|
-
├── config/
|
|
63
|
-
│ ├── types.ts # TypeScript
|
|
64
|
-
│ ├── endpoints.ts #
|
|
65
|
-
│ └── storage.ts #
|
|
66
|
-
└── utils/
|
|
67
|
-
├──
|
|
68
|
-
├──
|
|
69
|
-
|
|
71
|
+
├── index.ts # CLI 入口,使用 Commander.js
|
|
72
|
+
├── commands/ # CLI 命令实现
|
|
73
|
+
│ ├── run.ts # 核心启动逻辑,支持官方/提供商/配置模式
|
|
74
|
+
│ ├── list.ts # 列出可用端点
|
|
75
|
+
│ ├── add.ts # 添加自定义端点
|
|
76
|
+
│ ├── remove.ts # 删除自定义端点
|
|
77
|
+
│ └── proxy.ts # 代理管理(on/off/reset/status/help)
|
|
78
|
+
├── config/
|
|
79
|
+
│ ├── types.ts # TypeScript 接口定义
|
|
80
|
+
│ ├── endpoints.ts # 内置端点定义和模型映射
|
|
81
|
+
│ └── storage.ts # 配置文件 CRUD 操作
|
|
82
|
+
└── utils/
|
|
83
|
+
├── claude-settings.ts # Claude 配置读写、备份/恢复
|
|
84
|
+
├── launcher.ts # 进程启动和退出码处理
|
|
85
|
+
├── env.ts # ANTHROPIC_* 环境变量构建
|
|
86
|
+
├── passthrough-args.ts # -- 分隔符后的参数解析
|
|
87
|
+
└── output.ts # UTF-8 安全输出(修复中文显示)
|
|
70
88
|
```
|
|
71
89
|
|
|
72
|
-
|
|
90
|
+
### 关键设计决策
|
|
73
91
|
|
|
74
|
-
|
|
92
|
+
1. **UTF-8 处理**:在编译后的二进制文件中 monkey-patch `console.log/error` 确保中文字符正确显示
|
|
75
93
|
|
|
76
|
-
|
|
94
|
+
2. **临时修改模式**:启动官方 Claude 时临时清除第三方配置,退出后恢复
|
|
77
95
|
|
|
78
|
-
|
|
96
|
+
3. **环境变量策略**:使用 `ANTHROPIC_*` 环境变量而非文件修改来使用第三方 API
|
|
79
97
|
|
|
80
|
-
|
|
98
|
+
4. **模型映射**:支持将 Claude 模型层级(haiku/opus/sonnet)映射到提供商特定模型
|
|
81
99
|
|
|
82
|
-
|
|
100
|
+
5. **代理灵活性**:支持每会话代理配置,可选在官方模式下清除(clearForOfficial)
|
|
83
101
|
|
|
84
|
-
|
|
102
|
+
6. **参数透传**:通过 `--` 分隔符支持透传参数给 Claude CLI
|
|
85
103
|
|
|
86
|
-
|
|
87
|
-
1. 备份当前 Claude 配置
|
|
88
|
-
2. 清除第三方 endpoint 配置
|
|
89
|
-
3. 根据 `clearForOfficial` 决定是否清除 proxy
|
|
90
|
-
4. 启动 Claude(不设置第三方环境变量)
|
|
91
|
-
5. 退出后恢复配置
|
|
104
|
+
7. **交互式提示**:使用 Node.js readline 在未预配置时获取 token 和代理输入
|
|
92
105
|
|
|
93
|
-
|
|
94
|
-
1. 从内置或自定义 endpoints 查找配置
|
|
95
|
-
2. 获取 token(首次提示输入并保存)
|
|
96
|
-
3. 通过环境变量启动 Claude:
|
|
97
|
-
- `ANTHROPIC_BASE_URL`
|
|
98
|
-
- `ANTHROPIC_AUTH_TOKEN`
|
|
99
|
-
- `http_proxy`/`https_proxy`
|
|
106
|
+
## 测试策略
|
|
100
107
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
108
|
+
- **单元测试**:测试独立模块(storage、endpoints、env 等)
|
|
109
|
+
- **集成测试**:测试命令工作流(run、list、add、remove、proxy)
|
|
110
|
+
- **测试夹具**:`src/__tests__/fixtures/` 下的 mock 实现(mock-fs、mock-readline、mock-process)
|
|
111
|
+
- **环境隔离**:使用 `CC_RUN_TEST_HOME` 环境变量
|
|
112
|
+
- **手动测试**:`test/` 目录下的 dry-run、mock-claude、verify-passthrough
|
|
105
113
|
|
|
106
|
-
|
|
114
|
+
测试文件位于 `src/__tests__/`,使用 Bun Test 框架。
|
|
107
115
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
116
|
+
## 发布流程
|
|
117
|
+
|
|
118
|
+
项目包含自定义 **publish skill**,自动化 npm 发布:
|
|
119
|
+
1. 预检查(git 状态必须干净)
|
|
120
|
+
2. 版本 bump(`npm version`,创建 commit + tag)
|
|
121
|
+
3. 运行测试
|
|
122
|
+
4. 构建
|
|
123
|
+
5. 生成/更新 CHANGELOG
|
|
124
|
+
6. Git 提交
|
|
125
|
+
7. Git push(需用户确认)
|
|
126
|
+
8. 输出 `npm publish` 命令供手动执行
|
|
127
|
+
|
|
128
|
+
## 安装测试
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
./test-install.sh # 完整的安装/测试/卸载循环
|
|
132
|
+
```
|
|
113
133
|
|
|
114
|
-
|
|
134
|
+
## 技术栈
|
|
115
135
|
|
|
116
|
-
|
|
136
|
+
- **Runtime**: Bun
|
|
137
|
+
- **Language**: TypeScript (strict mode, ES2022 target)
|
|
138
|
+
- **CLI Framework**: Commander.js ^12.0.0
|
|
139
|
+
- **Testing**: Bun Test
|
|
140
|
+
- **Minimum Node**: >=18.0.0
|
|
141
|
+
- **License**: Apache-2.0
|
|
117
142
|
|
|
118
|
-
|
|
119
|
-
- **类型系统**: 严格模式 TypeScript
|
|
120
|
-
- **注释风格**: JSDoc 风格(中文)
|
|
121
|
-
- **错误处理**: 使用 `process.exit(1)` 终止,无异常抛出
|
|
122
|
-
- **文件组织**: 按功能分层,单一职责原则
|
|
123
|
-
- **命名约定**:
|
|
124
|
-
- 文件名: kebab-case (`claude-settings.ts`)
|
|
125
|
-
- 函数: camelCase
|
|
126
|
-
- 类型: PascalCase
|
|
127
|
-
- 常量: UPPER_SNAKE_CASE
|
|
143
|
+
## 内置 Endpoints
|
|
128
144
|
|
|
129
|
-
|
|
145
|
+
| 名称 | Endpoint |
|
|
146
|
+
|------|----------|
|
|
147
|
+
| glm | https://open.bigmodel.cn/api/paas/v4/ |
|
|
148
|
+
| deepseek | https://api.deepseek.com |
|
|
149
|
+
| minimax | https://api.minimax.chat/v1 |
|
|
130
150
|
|
|
131
|
-
|
|
132
|
-
使用 `spawn` 的 `env` 选项实现环境变量隔离,避免污染全局环境。
|
|
151
|
+
## Claude Code 技能
|
|
133
152
|
|
|
134
|
-
|
|
135
|
-
-
|
|
136
|
-
- 文件操作使用同步 API (`readFileSync`, `writeFileSync`)
|
|
137
|
-
- 目录不存在时自动创建 (`mkdirSync` with `recursive: true`)
|
|
153
|
+
项目在 `.claude/skills/` 中包含 Claude Code 技能:
|
|
154
|
+
- **publish** - 自动化 npm 发布工作流(预检查 → 版本 bump → 测试 → 构建 → CHANGELOG → 提交 → 推送)
|
|
138
155
|
|
|
139
|
-
|
|
140
|
-
`list.ts` 使用 `TextEncoder` 确保中文正确显示(标准 console.log 在某些环境下可能乱码)
|
|
156
|
+
这体现了项目的 dogfooding 方法——使用 Claude Code 工具管理自己的开发工作流。
|
|
141
157
|
|
|
142
|
-
|
|
143
|
-
使用 Node.js 原生 `readline` 模块实现 token 和代理地址输入
|
|
158
|
+
## 发布到 npm 的文件
|
|
144
159
|
|
|
145
|
-
|
|
160
|
+
- `dist/` - 编译后的 JavaScript
|
|
161
|
+
- `package.json` - 包元数据
|
|
162
|
+
- `README.md` - 用户文档
|
|
163
|
+
- `CHANGELOG.md` - 版本历史
|
|
146
164
|
|
|
147
|
-
|
|
148
|
-
2. **配置目录**: 自动创建 `~/.cc-run/` 和 `~/.claude/`
|
|
149
|
-
3. **Node 版本**: >= 18.0.0
|
|
165
|
+
**排除**:`src/`、`test/`、`*.test.ts`、`tsconfig.json`、`runcc` 二进制文件
|
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# runcc
|
|
2
2
|
|
|
3
3
|
Claude CLI 启动器,支持切换不同的 API endpoint。
|
|
4
4
|
|
|
@@ -24,19 +24,19 @@ npm install -g .
|
|
|
24
24
|
|
|
25
25
|
```bash
|
|
26
26
|
# 查看所有可用的 endpoints
|
|
27
|
-
|
|
27
|
+
runcc list
|
|
28
28
|
|
|
29
29
|
# 使用第三方 endpoint
|
|
30
|
-
|
|
30
|
+
runcc glm
|
|
31
31
|
|
|
32
32
|
# 配置原生 claude 命令使用 glm
|
|
33
|
-
|
|
33
|
+
runcc glm --claude
|
|
34
34
|
|
|
35
35
|
# 恢复原生 claude 使用官方 endpoint
|
|
36
|
-
|
|
36
|
+
runcc --claude
|
|
37
37
|
|
|
38
38
|
# 启动官方 claude
|
|
39
|
-
|
|
39
|
+
runcc
|
|
40
40
|
```
|
|
41
41
|
|
|
42
42
|
## 命令说明
|
|
@@ -45,29 +45,29 @@ cc-run
|
|
|
45
45
|
|
|
46
46
|
| 命令 | 说明 |
|
|
47
47
|
|------|------|
|
|
48
|
-
| `
|
|
49
|
-
| `
|
|
50
|
-
| `
|
|
51
|
-
| `
|
|
52
|
-
| `
|
|
53
|
-
| `
|
|
54
|
-
| `
|
|
48
|
+
| `runcc` | 启动官方 claude |
|
|
49
|
+
| `runcc glm` | 使用 glm endpoint |
|
|
50
|
+
| `runcc deepseek` | 使用 deepseek endpoint |
|
|
51
|
+
| `runcc minimax` | 使用 minimax endpoint |
|
|
52
|
+
| `runcc list` | 列出所有 endpoints |
|
|
53
|
+
| `runcc add <name> <endpoint> [token]` | 添加自定义 endpoint |
|
|
54
|
+
| `runcc remove <name>` | 删除自定义 endpoint |
|
|
55
55
|
|
|
56
56
|
### 原生命令配置
|
|
57
57
|
|
|
58
58
|
| 命令 | 说明 |
|
|
59
59
|
|------|------|
|
|
60
|
-
| `
|
|
61
|
-
| `
|
|
60
|
+
| `runcc <provider> --claude` | 配置原生 `claude` 命令使用第三方 endpoint |
|
|
61
|
+
| `runcc --claude` | 恢复原生 `claude` 命令使用官方 endpoint |
|
|
62
62
|
|
|
63
63
|
### 代理管理
|
|
64
64
|
|
|
65
65
|
| 命令 | 说明 |
|
|
66
66
|
|------|------|
|
|
67
|
-
| `
|
|
68
|
-
| `
|
|
69
|
-
| `
|
|
70
|
-
| `
|
|
67
|
+
| `runcc proxy on` | 开启代理 |
|
|
68
|
+
| `runcc proxy off` | 关闭代理 |
|
|
69
|
+
| `runcc proxy status` | 查看代理状态 |
|
|
70
|
+
| `runcc proxy reset` | 重置代理配置 |
|
|
71
71
|
|
|
72
72
|
## 内置 Endpoints
|
|
73
73
|
|
|
@@ -79,7 +79,7 @@ cc-run
|
|
|
79
79
|
|
|
80
80
|
## 配置文件
|
|
81
81
|
|
|
82
|
-
### ~/.
|
|
82
|
+
### ~/.runcc/config.json
|
|
83
83
|
|
|
84
84
|
```json
|
|
85
85
|
{
|
|
@@ -117,46 +117,46 @@ cc-run
|
|
|
117
117
|
### 添加自定义 endpoint
|
|
118
118
|
|
|
119
119
|
```bash
|
|
120
|
-
|
|
120
|
+
runcc add my-api https://api.my-service.com/v1 sk-my-token
|
|
121
121
|
```
|
|
122
122
|
|
|
123
123
|
### 切换 endpoint
|
|
124
124
|
|
|
125
125
|
```bash
|
|
126
126
|
# 使用 glm
|
|
127
|
-
|
|
127
|
+
runcc glm
|
|
128
128
|
|
|
129
129
|
# 使用 deepseek
|
|
130
|
-
|
|
130
|
+
runcc deepseek
|
|
131
131
|
|
|
132
132
|
# 使用自定义 endpoint
|
|
133
|
-
|
|
133
|
+
runcc my-api
|
|
134
134
|
```
|
|
135
135
|
|
|
136
136
|
### 配置代理
|
|
137
137
|
|
|
138
138
|
```bash
|
|
139
139
|
# 开启代理(首次会提示输入代理地址)
|
|
140
|
-
|
|
140
|
+
runcc proxy on
|
|
141
141
|
|
|
142
142
|
# 查看代理状态
|
|
143
|
-
|
|
143
|
+
runcc proxy status
|
|
144
144
|
|
|
145
145
|
# 关闭代理
|
|
146
|
-
|
|
146
|
+
runcc proxy off
|
|
147
147
|
```
|
|
148
148
|
|
|
149
149
|
### 配置原生命令
|
|
150
150
|
|
|
151
151
|
```bash
|
|
152
152
|
# 让原生 claude 命令使用 glm
|
|
153
|
-
|
|
153
|
+
runcc glm --claude
|
|
154
154
|
|
|
155
155
|
# 之后直接使用 claude 命令即可
|
|
156
156
|
claude "你好"
|
|
157
157
|
|
|
158
158
|
# 恢复使用官方 endpoint
|
|
159
|
-
|
|
159
|
+
runcc --claude
|
|
160
160
|
```
|
|
161
161
|
|
|
162
162
|
## Token 管理
|
|
@@ -164,11 +164,11 @@ cc-run --claude
|
|
|
164
164
|
首次使用某个 endpoint 时,如果未配置 token,会提示输入:
|
|
165
165
|
|
|
166
166
|
```bash
|
|
167
|
-
$
|
|
167
|
+
$ runcc glm
|
|
168
168
|
请输入 glm 的 API Token: [输入框]
|
|
169
169
|
```
|
|
170
170
|
|
|
171
|
-
Token 会被保存到 `~/.
|
|
171
|
+
Token 会被保存到 `~/.runcc/config.json`,下次使用时无需再次输入。
|
|
172
172
|
|
|
173
173
|
## 开发
|
|
174
174
|
|
package/dist/index.js
CHANGED
|
@@ -1917,7 +1917,7 @@ import { join } from "node:path";
|
|
|
1917
1917
|
import { homedir } from "node:os";
|
|
1918
1918
|
function getConfigDir() {
|
|
1919
1919
|
const home = process.env.CC_RUN_TEST_HOME || homedir();
|
|
1920
|
-
return join(home, ".
|
|
1920
|
+
return join(home, ".runcc");
|
|
1921
1921
|
}
|
|
1922
1922
|
function getConfigFilePath() {
|
|
1923
1923
|
return join(getConfigDir(), "config.json");
|
|
@@ -2215,7 +2215,7 @@ function proxyReset() {
|
|
|
2215
2215
|
function proxyStatus() {
|
|
2216
2216
|
const ccRunConfig = getProxyConfig();
|
|
2217
2217
|
const claudeProxy = getClaudeProxy();
|
|
2218
|
-
console.log("
|
|
2218
|
+
console.log("RunCC 代理配置:");
|
|
2219
2219
|
console.log(` 状态: ${ccRunConfig.enabled ? "开启" : "关闭"}`);
|
|
2220
2220
|
if (ccRunConfig.url) {
|
|
2221
2221
|
console.log(` 地址: ${ccRunConfig.url}`);
|
|
@@ -2235,16 +2235,16 @@ function proxyHelp() {
|
|
|
2235
2235
|
console.log(`
|
|
2236
2236
|
代理管理命令:
|
|
2237
2237
|
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2238
|
+
runcc proxy on 开启代理(首次会提示输入代理地址)
|
|
2239
|
+
runcc proxy off 关闭代理
|
|
2240
|
+
runcc proxy reset 重置代理配置
|
|
2241
|
+
runcc proxy status 查看代理状态
|
|
2242
|
+
runcc proxy help 显示此帮助信息
|
|
2243
2243
|
|
|
2244
2244
|
说明:
|
|
2245
2245
|
- proxy on 会修改 ~/.claude/settings.json,添加 proxy 配置
|
|
2246
2246
|
- proxy off 会删除 ~/.claude/settings.json 中的 proxy 配置
|
|
2247
|
-
- 代理地址保存在 ~/.
|
|
2247
|
+
- 代理地址保存在 ~/.runcc/config.json 中
|
|
2248
2248
|
`);
|
|
2249
2249
|
}
|
|
2250
2250
|
async function promptProxyUrl() {
|
|
@@ -2360,7 +2360,7 @@ async function runProvider(providerName, configureClaude, passthroughArgs = [])
|
|
|
2360
2360
|
const endpoint = getEndpointConfig(providerName);
|
|
2361
2361
|
if (!endpoint) {
|
|
2362
2362
|
console.error(`错误: 未找到 endpoint "${providerName}"`);
|
|
2363
|
-
console.log('使用 "
|
|
2363
|
+
console.log('使用 "runcc list" 查看可用的 endpoints');
|
|
2364
2364
|
process.exit(1);
|
|
2365
2365
|
}
|
|
2366
2366
|
let token = endpoint.token || getToken(providerName);
|
|
@@ -2386,7 +2386,7 @@ async function runProvider(providerName, configureClaude, passthroughArgs = [])
|
|
|
2386
2386
|
if (configureClaude) {
|
|
2387
2387
|
setThirdPartyApi(endpoint.endpoint, token);
|
|
2388
2388
|
console.log(`已配置原生 claude 命令使用 ${providerName}`);
|
|
2389
|
-
console.log('使用 "
|
|
2389
|
+
console.log('使用 "runcc --claude" 可恢复官方配置');
|
|
2390
2390
|
}
|
|
2391
2391
|
const child = launchClaude({
|
|
2392
2392
|
apiEndpoint: endpoint.endpoint,
|
|
@@ -2452,7 +2452,7 @@ function validateDashPosition(argv) {
|
|
|
2452
2452
|
return;
|
|
2453
2453
|
}
|
|
2454
2454
|
if (dashIndex === 0) {
|
|
2455
|
-
|
|
2455
|
+
return;
|
|
2456
2456
|
}
|
|
2457
2457
|
const beforeDash = userArgs.slice(0, dashIndex);
|
|
2458
2458
|
const hasValidPrefix = beforeDash.some((arg) => !arg.startsWith("-") || arg === "--claude");
|
|
@@ -2482,7 +2482,7 @@ if (isBunCompiled) {
|
|
|
2482
2482
|
};
|
|
2483
2483
|
}
|
|
2484
2484
|
var program2 = new Command;
|
|
2485
|
-
program2.name("
|
|
2485
|
+
program2.name("runcc").description("Claude 启动器 - 支持切换不同的 API endpoint").version("0.1.0");
|
|
2486
2486
|
program2.command("list").description("列出所有可用的 endpoints").action(list);
|
|
2487
2487
|
program2.command("add").description("添加自定义 endpoint").argument("<name>", "endpoint 名称").argument("<endpoint>", "API 地址").action(add);
|
|
2488
2488
|
program2.command("remove").description("删除自定义 endpoint").argument("<name>", "endpoint 名称").action(remove);
|
|
@@ -2510,9 +2510,10 @@ program2.argument("[provider]", "provider 名称 (glm, deepseek, minimax 或自
|
|
|
2510
2510
|
console.error("❌ 参数位置不正确");
|
|
2511
2511
|
console.error("");
|
|
2512
2512
|
console.error("正确的用法示例:");
|
|
2513
|
-
console.error("
|
|
2514
|
-
console.error("
|
|
2515
|
-
console.error("
|
|
2513
|
+
console.error(" runcc -- <claude参数> # 启动官方 Claude 并透传参数");
|
|
2514
|
+
console.error(" runcc glm -- <claude参数> # 使用 glm provider 并透传参数");
|
|
2515
|
+
console.error(" runcc --claude -- <参数> # 恢复官方配置并透传参数");
|
|
2516
|
+
console.error(" runcc glm --claude -- <参数> # 配置原生 claude 命令使用 glm");
|
|
2516
2517
|
console.error("");
|
|
2517
2518
|
console.error("说明: -- 分隔符用于将后续参数透传给 Claude CLI");
|
|
2518
2519
|
process.exit(1);
|
|
@@ -2520,4 +2521,9 @@ program2.argument("[provider]", "provider 名称 (glm, deepseek, minimax 或自
|
|
|
2520
2521
|
throw error;
|
|
2521
2522
|
}
|
|
2522
2523
|
});
|
|
2523
|
-
|
|
2524
|
+
var userArgs = process.argv.slice(2);
|
|
2525
|
+
if (userArgs[0] === "--") {
|
|
2526
|
+
program2.parse([process.argv[0], process.argv[1]]);
|
|
2527
|
+
} else {
|
|
2528
|
+
program2.parse();
|
|
2529
|
+
}
|
package/package.json
CHANGED
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: npm-publish
|
|
3
|
-
description: Automate npm package version bumping and publishing with comprehensive safety checks. Use when user requests "发布新版本", "publish to npm", "bump version", "release a new version", or similar package publishing tasks. Supports semantic versioning (patch/minor/major), git tagging, CHANGELOG updates, and pre-publish validation.
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# NPM Publish
|
|
7
|
-
|
|
8
|
-
Automate the complete npm package release workflow with safety checks, version management, and changelog updates.
|
|
9
|
-
|
|
10
|
-
## Workflow
|
|
11
|
-
|
|
12
|
-
Follow this sequential workflow for publishing npm packages. Each step includes validation and confirmation points to ensure safe releases.
|
|
13
|
-
|
|
14
|
-
### Step 1: Pre-flight Checks
|
|
15
|
-
|
|
16
|
-
Before starting the release process, create a todo list with these items and verify the environment:
|
|
17
|
-
|
|
18
|
-
1. **检查 git 工作区状态**
|
|
19
|
-
- Run `git status` to ensure working directory is clean
|
|
20
|
-
- If there are uncommitted changes, ask user whether to commit them or abort
|
|
21
|
-
|
|
22
|
-
2. **确认当前分支**
|
|
23
|
-
- Check current branch with `git branch --show-current`
|
|
24
|
-
- Verify it's `main` or `master` (or other release branch)
|
|
25
|
-
- If not on release branch, warn user and ask to confirm or switch
|
|
26
|
-
|
|
27
|
-
3. **检查 npm 登录状态**
|
|
28
|
-
- Run `npm whoami` to verify npm authentication
|
|
29
|
-
- If not logged in, instruct user to run `npm login`
|
|
30
|
-
|
|
31
|
-
4. **拉取最新代码**
|
|
32
|
-
- Run `git pull` to ensure working with latest code
|
|
33
|
-
- Check for any conflicts
|
|
34
|
-
|
|
35
|
-
### Step 2: Determine Version Bump Type
|
|
36
|
-
|
|
37
|
-
Ask the user which type of version bump to perform, unless they've already specified:
|
|
38
|
-
|
|
39
|
-
- **patch**: Bug fixes, minor changes (1.0.0 → 1.0.1)
|
|
40
|
-
- **minor**: New features, backward compatible (1.0.0 → 1.1.0)
|
|
41
|
-
- **major**: Breaking changes (1.0.0 → 2.0.0)
|
|
42
|
-
- **custom**: Specify exact version number
|
|
43
|
-
|
|
44
|
-
Use the `AskUserQuestion` tool if the version type wasn't specified in the initial request.
|
|
45
|
-
|
|
46
|
-
### Step 3: Run Tests and Build
|
|
47
|
-
|
|
48
|
-
Execute the project's quality checks:
|
|
49
|
-
|
|
50
|
-
1. **运行测试**
|
|
51
|
-
- Check if `package.json` has a `test` script
|
|
52
|
-
- Run `npm test` or equivalent command
|
|
53
|
-
- If tests fail, abort the release and report errors
|
|
54
|
-
|
|
55
|
-
2. **运行构建**
|
|
56
|
-
- Check if `package.json` has a `build` script
|
|
57
|
-
- Run `npm run build` or equivalent command
|
|
58
|
-
- If build fails, abort the release and report errors
|
|
59
|
-
|
|
60
|
-
### Step 4: Update CHANGELOG
|
|
61
|
-
|
|
62
|
-
If CHANGELOG.md exists in the project:
|
|
63
|
-
|
|
64
|
-
1. **Read recent commits**
|
|
65
|
-
- Run `git log` to see commits since last release
|
|
66
|
-
- Look for previous version tags with `git tag -l`
|
|
67
|
-
|
|
68
|
-
2. **Generate changelog entry**
|
|
69
|
-
- Create a new section for the new version
|
|
70
|
-
- List key changes based on commit messages
|
|
71
|
-
- Format: `## [Version] - YYYY-MM-DD`
|
|
72
|
-
- Group changes by type: Features, Bug Fixes, Breaking Changes, etc.
|
|
73
|
-
|
|
74
|
-
3. **Let user review and edit**
|
|
75
|
-
- Show the generated changelog entry
|
|
76
|
-
- Use `AskUserQuestion` to confirm or request modifications
|
|
77
|
-
- Update CHANGELOG.md with the approved content
|
|
78
|
-
|
|
79
|
-
If no CHANGELOG.md exists, ask user if they want to create one.
|
|
80
|
-
|
|
81
|
-
### Step 5: Bump Version
|
|
82
|
-
|
|
83
|
-
Use npm's built-in version command:
|
|
84
|
-
|
|
85
|
-
```bash
|
|
86
|
-
npm version <patch|minor|major|x.y.z> -m "chore: release v%s"
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
This command will:
|
|
90
|
-
- Update version in `package.json` and `package-lock.json`
|
|
91
|
-
- Create a git commit with the specified message
|
|
92
|
-
- Create a git tag with the new version
|
|
93
|
-
|
|
94
|
-
### Step 6: User Confirmation
|
|
95
|
-
|
|
96
|
-
Before publishing, display a summary and ask for final confirmation:
|
|
97
|
-
|
|
98
|
-
```
|
|
99
|
-
Ready to publish:
|
|
100
|
-
- Package: <package-name>
|
|
101
|
-
- Current version: <old-version>
|
|
102
|
-
- New version: <new-version>
|
|
103
|
-
- Branch: <branch-name>
|
|
104
|
-
- Changes: <summary from changelog>
|
|
105
|
-
|
|
106
|
-
Proceed with publishing? (yes/no)
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
Use `AskUserQuestion` for this confirmation.
|
|
110
|
-
|
|
111
|
-
### Step 7: Publish to NPM
|
|
112
|
-
|
|
113
|
-
If user confirms, publish the package:
|
|
114
|
-
|
|
115
|
-
```bash
|
|
116
|
-
npm publish
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
Options to consider:
|
|
120
|
-
- `--access public` for scoped public packages
|
|
121
|
-
- `--tag <tag>` for pre-release versions (e.g., `beta`, `next`)
|
|
122
|
-
- `--dry-run` to test without actually publishing (useful for first-time testing)
|
|
123
|
-
|
|
124
|
-
### Step 8: Push to Git Remote
|
|
125
|
-
|
|
126
|
-
After successful npm publish:
|
|
127
|
-
|
|
128
|
-
1. **推送代码和标签**
|
|
129
|
-
```bash
|
|
130
|
-
git push && git push --tags
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
2. **验证发布**
|
|
134
|
-
- Confirm the new version appears on npmjs.com
|
|
135
|
-
- Confirm the git tag appears on the remote repository
|
|
136
|
-
|
|
137
|
-
### Step 9: Summary
|
|
138
|
-
|
|
139
|
-
Report the successful release:
|
|
140
|
-
|
|
141
|
-
```
|
|
142
|
-
✅ Successfully published <package-name>@<new-version>
|
|
143
|
-
|
|
144
|
-
- NPM: https://www.npmjs.com/package/<package-name>
|
|
145
|
-
- Git tag: <tag-name>
|
|
146
|
-
- Changelog updated: Yes/No
|
|
147
|
-
|
|
148
|
-
Next steps:
|
|
149
|
-
- Create GitHub release (if applicable)
|
|
150
|
-
- Announce to team
|
|
151
|
-
- Update dependent projects
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
## Error Handling
|
|
155
|
-
|
|
156
|
-
If any step fails:
|
|
157
|
-
|
|
158
|
-
1. **Clearly state which step failed and why**
|
|
159
|
-
2. **Do not proceed to next steps**
|
|
160
|
-
3. **Provide actionable recovery steps**
|
|
161
|
-
4. **If version was bumped but publish failed:**
|
|
162
|
-
- The version commit and tag already exist
|
|
163
|
-
- User can either: fix the issue and run `npm publish` manually, or reset with `git reset --hard HEAD~1 && git tag -d v<version>`
|
|
164
|
-
|
|
165
|
-
## Rollback
|
|
166
|
-
|
|
167
|
-
If user needs to undo a release:
|
|
168
|
-
|
|
169
|
-
1. **Unpublish from npm** (only within 72 hours):
|
|
170
|
-
```bash
|
|
171
|
-
npm unpublish <package-name>@<version>
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
2. **Delete git tag**:
|
|
175
|
-
```bash
|
|
176
|
-
git tag -d v<version>
|
|
177
|
-
git push origin :refs/tags/v<version>
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
3. **Revert version commit**:
|
|
181
|
-
```bash
|
|
182
|
-
git reset --hard HEAD~1
|
|
183
|
-
git push --force
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
**Warning**: Unpublishing is discouraged by npm. Prefer deprecating instead:
|
|
187
|
-
```bash
|
|
188
|
-
npm deprecate <package-name>@<version> "Reason for deprecation"
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
## Customization
|
|
192
|
-
|
|
193
|
-
Different projects may need adaptations:
|
|
194
|
-
|
|
195
|
-
- **Monorepo**: Use tools like `lerna` or `nx` for versioning multiple packages
|
|
196
|
-
- **Pre-release versions**: Use `npm version prerelease --preid=beta`
|
|
197
|
-
- **CI/CD**: This workflow is for manual releases; adapt for automated pipelines
|
|
198
|
-
- **Private registry**: Use `--registry` flag or `.npmrc` configuration
|
|
199
|
-
- **2FA**: npm may require OTP code during publish, prompt user to enter it
|
|
200
|
-
|
|
201
|
-
## Best Practices
|
|
202
|
-
|
|
203
|
-
1. **Always run tests before publishing**
|
|
204
|
-
2. **Keep CHANGELOG.md up to date**
|
|
205
|
-
3. **Use semantic versioning correctly**
|
|
206
|
-
4. **Review changes one final time before confirming**
|
|
207
|
-
5. **Never publish with uncommitted changes**
|
|
208
|
-
6. **Tag releases for easy reference**
|
|
209
|
-
7. **Announce breaking changes clearly**
|
package/PLAN.md
DELETED
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
# CC 启动器实现计划
|
|
2
|
-
|
|
3
|
-
## 项目概述
|
|
4
|
-
|
|
5
|
-
使用 TypeScript + bun 创建 CC 启动器,支持切换不同的 API endpoint。
|
|
6
|
-
|
|
7
|
-
## 命令格式
|
|
8
|
-
|
|
9
|
-
| 命令 | 功能 |
|
|
10
|
-
|------|------|
|
|
11
|
-
| `cc-run` | **总是**启动官方 claude(根据配置决定是否临时清除 proxy 和第三方 endpoint) |
|
|
12
|
-
| `cc-run --claude` | 恢复原生 `claude` 命令使用官方 endpoint(删除 ~/.claude/settings.json 中的第三方配置) |
|
|
13
|
-
| `cc-run glm` | 使用 glm endpoint |
|
|
14
|
-
| `cc-run glm --claude` | 使用 glm,并配置原生 `claude` 命令默认使用 glm |
|
|
15
|
-
| `cc-run deepseek` | 使用 deepseek endpoint |
|
|
16
|
-
| `cc-run deepseek --claude` | 使用 deepseek,并配置原生 `claude` 命令默认使用 deepseek |
|
|
17
|
-
| `cc-run minimax` | 使用 minimax endpoint |
|
|
18
|
-
| `cc-run add <name> <endpoint> <token>` | 添加自定义 endpoint |
|
|
19
|
-
| `cc-run list` | 列出所有 endpoint |
|
|
20
|
-
| `cc-run remove <name>` | 删除自定义 endpoint |
|
|
21
|
-
| `cc-run proxy on` | 开启代理(修改 ~/.claude/settings.json) |
|
|
22
|
-
| `cc-run proxy off` | 关闭代理(修改 ~/.claude/settings.json) |
|
|
23
|
-
| `cc-run proxy reset` | 重置代理配置 |
|
|
24
|
-
| `cc-run proxy status` | 查看代理状态 |
|
|
25
|
-
| `cc-run proxy help` | 代理帮助信息 |
|
|
26
|
-
|
|
27
|
-
## 项目结构
|
|
28
|
-
|
|
29
|
-
```
|
|
30
|
-
cc-run/
|
|
31
|
-
├── package.json
|
|
32
|
-
├── tsconfig.json
|
|
33
|
-
├── src/
|
|
34
|
-
│ ├── index.ts # CLI 入口
|
|
35
|
-
│ ├── commands/
|
|
36
|
-
│ │ ├── run.ts # 启动命令
|
|
37
|
-
│ │ ├── add.ts # 添加 endpoint
|
|
38
|
-
│ │ ├── list.ts # 列出 endpoint
|
|
39
|
-
│ │ ├── remove.ts # 删除 endpoint
|
|
40
|
-
│ │ └── proxy.ts # 代理管理命令
|
|
41
|
-
│ ├── config/
|
|
42
|
-
│ │ ├── storage.ts # 配置存储管理
|
|
43
|
-
│ │ ├── endpoints.ts # 内置 endpoint 定义
|
|
44
|
-
│ │ └── types.ts # 类型定义
|
|
45
|
-
│ └── utils/
|
|
46
|
-
│ ├── env.ts # 环境变量设置
|
|
47
|
-
│ └── launcher.ts # 启动 claude
|
|
48
|
-
└── README.md
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
## 内置 Endpoints
|
|
52
|
-
|
|
53
|
-
| 名称 | Endpoint |
|
|
54
|
-
|------|----------|
|
|
55
|
-
| glm | https://open.bigmodel.cn/api/paas/v4/ |
|
|
56
|
-
| deepseek | https://api.deepseek.com |
|
|
57
|
-
| minimax | https://api.minimax.chat/v1 |
|
|
58
|
-
|
|
59
|
-
## 配置存储
|
|
60
|
-
|
|
61
|
-
### ~/.cc-run/config.json(启动器配置)
|
|
62
|
-
`proxy.on/off` 会修改此文件的 proxy 配置,`cc-run <provider>` 会保存 token:
|
|
63
|
-
```json
|
|
64
|
-
{
|
|
65
|
-
"endpoints": [
|
|
66
|
-
{
|
|
67
|
-
"name": "my-custom",
|
|
68
|
-
"endpoint": "https://api.example.com/v1",
|
|
69
|
-
"token": "sk-xxxxxxxx"
|
|
70
|
-
}
|
|
71
|
-
],
|
|
72
|
-
"tokens": {
|
|
73
|
-
"glm": "sk-xxxxxxxx",
|
|
74
|
-
"deepseek": "sk-yyyyyyyy",
|
|
75
|
-
"minimax": "sk-zzzzzzzz"
|
|
76
|
-
},
|
|
77
|
-
"lastUsed": "glm",
|
|
78
|
-
"proxy": {
|
|
79
|
-
"enabled": true,
|
|
80
|
-
"url": "http://agent.baidu.com:8891",
|
|
81
|
-
"clearForOfficial": false
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
### ~/.claude/settings.json(Claude 官方配置)
|
|
87
|
-
`proxy on/off` 会修改此文件的 proxy 配置:
|
|
88
|
-
```json
|
|
89
|
-
{
|
|
90
|
-
"proxy": "http://agent.baidu.com:8891"
|
|
91
|
-
}
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
## Proxy 处理逻辑
|
|
95
|
-
|
|
96
|
-
### cc-run proxy on
|
|
97
|
-
1. 提示输入代理地址(首次)
|
|
98
|
-
2. 保存到 `~/.cc-run/config.json`
|
|
99
|
-
3. 修改 `~/.claude/settings.json`,添加 proxy 配置
|
|
100
|
-
|
|
101
|
-
### cc-run proxy off
|
|
102
|
-
1. 更新 `~/.cc-run/config.json`(enabled: false)
|
|
103
|
-
2. 修改 `~/.claude/settings.json`,删除 proxy 配置
|
|
104
|
-
|
|
105
|
-
## 运行逻辑
|
|
106
|
-
|
|
107
|
-
### cc-run(无参数)
|
|
108
|
-
|
|
109
|
-
总是启动官方 claude。启动前会检查并清理 `~/.claude/settings.json`:
|
|
110
|
-
|
|
111
|
-
1. 读取当前的 `~/.claude/settings.json`
|
|
112
|
-
2. 检查是否有 `proxy` 配置
|
|
113
|
-
3. 检查是否有 `apiUrl` / `anthropicApiKey` 等第三方 endpoint 配置
|
|
114
|
-
4. 根据清理策略清理:
|
|
115
|
-
- **proxy 清理**:由 `~/.cc-run/config.json` 中 `proxy.clearForOfficial` 决定
|
|
116
|
-
- **endpoint 清理**:总是清除第三方 endpoint 配置
|
|
117
|
-
5. 启动 claude
|
|
118
|
-
6. claude 退出后恢复被清除的配置
|
|
119
|
-
|
|
120
|
-
**proxy 清理策略**(`~/.cc-run/config.json`):
|
|
121
|
-
```json
|
|
122
|
-
{
|
|
123
|
-
"proxy": {
|
|
124
|
-
"clearForOfficial": true // 启动官方 claude 时是否清除 proxy
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
### cc-run <provider>
|
|
130
|
-
|
|
131
|
-
使用指定 endpoint,通过环境变量启动。
|
|
132
|
-
|
|
133
|
-
**Token 获取逻辑**:
|
|
134
|
-
1. 检查 `~/.cc-run/config.json` 中是否已保存该 provider 的 token
|
|
135
|
-
2. 如果没有,提示用户输入:
|
|
136
|
-
```
|
|
137
|
-
请输入 glm 的 API Token: [输入框]
|
|
138
|
-
```
|
|
139
|
-
3. 保存 token 到 `~/.cc-run/config.json`:
|
|
140
|
-
```json
|
|
141
|
-
{
|
|
142
|
-
"tokens": {
|
|
143
|
-
"glm": "sk-xxxxxxxx",
|
|
144
|
-
"deepseek": "sk-yyyyyyyy",
|
|
145
|
-
"minimax": "sk-zzzzzzzz"
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
```
|
|
149
|
-
4. 使用保存的 token 启动
|
|
150
|
-
|
|
151
|
-
### cc-run <provider> --claude
|
|
152
|
-
使用指定 endpoint,并**配置原生 `claude` 命令**的默认行为:
|
|
153
|
-
1. 使用指定 endpoint 启动 cc-run
|
|
154
|
-
2. 修改 `~/.claude/settings.json`,设置:
|
|
155
|
-
- `apiUrl`: 指定 provider 的 endpoint
|
|
156
|
-
- `anthropicApiKey`: 指定 provider 的 token
|
|
157
|
-
3. 之后直接运行原生 `claude` 命令时,会使用这个第三方 endpoint
|
|
158
|
-
4. **不影响** `cc-run` 无参数的行为(`cc-run` 仍然总是启动官方 claude)
|
|
159
|
-
|
|
160
|
-
### cc-run --claude(无 provider)
|
|
161
|
-
**恢复原生 `claude` 命令使用官方 endpoint**:
|
|
162
|
-
1. 删除 `~/.claude/settings.json` 中的 `apiUrl` 和 `anthropicApiKey`
|
|
163
|
-
2. 之后直接运行原生 `claude` 命令时,会使用官方 endpoint
|
|
164
|
-
3. 不启动 cc-run
|
|
165
|
-
|
|
166
|
-
> **注**:`--claude` 只影响原生 `claude` 命令,不影响 `cc-run`
|
|
167
|
-
|
|
168
|
-
## 环境变量
|
|
169
|
-
|
|
170
|
-
启动 CC 时设置:
|
|
171
|
-
- `ANTHROPIC_BASE_URL` - API endpoint
|
|
172
|
-
- `ANTHROPIC_AUTH_TOKEN` - API token
|
|
173
|
-
- `http_proxy` / `https_proxy` - 代理(如果配置)
|
|
174
|
-
|
|
175
|
-
## 关键文件
|
|
176
|
-
|
|
177
|
-
| 文件 | 说明 |
|
|
178
|
-
|------|------|
|
|
179
|
-
| `src/index.ts` | CLI 入口,使用 commander 解析参数 |
|
|
180
|
-
| `src/config/storage.ts` | 配置文件读写、token 管理、endpoint 管理 |
|
|
181
|
-
| `src/utils/token.ts` | Token 获取和保存逻辑(首次使用时提示输入) |
|
|
182
|
-
| `src/commands/run.ts` | 核心启动逻辑,处理官方模式的 proxy 临时清除 |
|
|
183
|
-
| `src/commands/proxy.ts` | 代理管理命令(on/off/reset/status/help) |
|
|
184
|
-
| `src/utils/launcher.ts` | spawn claude 进程 |
|
|
185
|
-
| `src/utils/claude-settings.ts` | 读写 `~/.claude/settings.json` 的 proxy 和 endpoint 配置 |
|
|
186
|
-
| `src/config/types.ts` | TypeScript 类型定义 |
|
|
187
|
-
|
|
188
|
-
## 代理命令实现要点
|
|
189
|
-
|
|
190
|
-
| 命令 | 说明 |
|
|
191
|
-
|------|------|
|
|
192
|
-
| `cc-run proxy on` | 首次运行时提示输入代理地址,保存并修改 `~/.claude/settings.json` |
|
|
193
|
-
| `cc-run proxy off` | 关闭代理,删除 `~/.claude/settings.json` 中的 proxy 配置 |
|
|
194
|
-
| `cc-run proxy reset` | 重置代理配置 |
|
|
195
|
-
| `cc-run proxy status` | 显示代理状态(是否启用、地址) |
|
|
196
|
-
| `cc-run proxy help` | 显示代理相关帮助 |
|
|
197
|
-
|
|
198
|
-
## 依赖
|
|
199
|
-
|
|
200
|
-
```json
|
|
201
|
-
{
|
|
202
|
-
"dependencies": {
|
|
203
|
-
"commander": "^12.0.0"
|
|
204
|
-
},
|
|
205
|
-
"devDependencies": {
|
|
206
|
-
"@types/node": "^20.0.0",
|
|
207
|
-
"bun-types": "latest"
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
## 验证方式
|
|
213
|
-
|
|
214
|
-
```bash
|
|
215
|
-
# 1. 构建
|
|
216
|
-
bun run build
|
|
217
|
-
|
|
218
|
-
# 2. 测试 list
|
|
219
|
-
bun run src/index.ts list
|
|
220
|
-
|
|
221
|
-
# 3. 测试 add
|
|
222
|
-
bun run src/index.ts add test https://api.test.com sk-test
|
|
223
|
-
|
|
224
|
-
# 4. 测试 proxy
|
|
225
|
-
bun run src/index.ts proxy status
|
|
226
|
-
bun run src/index.ts proxy on
|
|
227
|
-
bun run src/index.ts proxy off
|
|
228
|
-
|
|
229
|
-
# 5. 测试 run(需要已有 token)
|
|
230
|
-
bun run src/index.ts glm
|
|
231
|
-
|
|
232
|
-
# 6. 全局安装后测试
|
|
233
|
-
bun install -g
|
|
234
|
-
cc-run list
|
|
235
|
-
cc-run proxy status
|
|
236
|
-
```
|