ccman 0.0.1
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/.editorconfig +15 -0
- package/.eslintrc.js +28 -0
- package/.github/workflows/release.yml +213 -0
- package/.prettierrc +10 -0
- package/CLAUDE.md +215 -0
- package/README.md +361 -0
- package/README_zh.md +361 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +476 -0
- package/dist/cli.js.map +1 -0
- package/dist/config/ConfigManager.d.ts +67 -0
- package/dist/config/ConfigManager.d.ts.map +1 -0
- package/dist/config/ConfigManager.js +226 -0
- package/dist/config/ConfigManager.js.map +1 -0
- package/dist/config/EnvironmentManager.d.ts +83 -0
- package/dist/config/EnvironmentManager.d.ts.map +1 -0
- package/dist/config/EnvironmentManager.js +280 -0
- package/dist/config/EnvironmentManager.js.map +1 -0
- package/dist/config/constants.d.ts +40 -0
- package/dist/config/constants.d.ts.map +1 -0
- package/dist/config/constants.js +97 -0
- package/dist/config/constants.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/shell/ShellManager.d.ts +73 -0
- package/dist/shell/ShellManager.d.ts.map +1 -0
- package/dist/shell/ShellManager.js +391 -0
- package/dist/shell/ShellManager.js.map +1 -0
- package/dist/types/index.d.ts +55 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +6 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/version.d.ts +67 -0
- package/dist/utils/version.d.ts.map +1 -0
- package/dist/utils/version.js +199 -0
- package/dist/utils/version.js.map +1 -0
- package/docs/npm-publish-guide.md +71 -0
- package/docs/release-guide.md +86 -0
- package/docs/version-management.md +64 -0
- package/jest.config.js +22 -0
- package/package.json +57 -0
- package/release-temp/README.md +361 -0
- package/release-temp/package.json +57 -0
- package/scripts/publish-local.sh +91 -0
- package/scripts/quick-release.sh +100 -0
- package/scripts/release.sh +430 -0
- package/src/cli.ts +510 -0
- package/src/config/ConfigManager.ts +227 -0
- package/src/config/EnvironmentManager.ts +327 -0
- package/src/config/constants.ts +64 -0
- package/src/index.ts +5 -0
- package/src/shell/ShellManager.ts +416 -0
- package/src/types/index.ts +60 -0
- package/src/utils/version.ts +189 -0
- package/tsconfig.json +25 -0
package/README.md
ADDED
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
# CCM - Claude Code Manager
|
|
2
|
+
|
|
3
|
+
A TypeScript-based command-line tool to manage Claude Code API configurations with **safe shell integration** through independent configuration files.
|
|
4
|
+
|
|
5
|
+
> **English Documentation** | [中文文档](./README_zh.md)
|
|
6
|
+
|
|
7
|
+
## ✨ Features
|
|
8
|
+
|
|
9
|
+
✅ **Environment Group Management** - Add, remove, switch between Claude Code environments
|
|
10
|
+
✅ **Safe Shell Integration** - Uses independent `~/.ccman/.ccmanrc` file to avoid modifying user configs
|
|
11
|
+
✅ **Interactive Source Control** - Choose manual or automatic source with risk warnings
|
|
12
|
+
✅ **Type Safety** - Full TypeScript implementation with strict typing
|
|
13
|
+
✅ **Interactive CLI** - User-friendly commands with colored output and inquirer prompts
|
|
14
|
+
✅ **Multi-Shell Support** - Works with bash, zsh, and fish
|
|
15
|
+
✅ **Complete Workflow** - From setup to usage in one seamless flow
|
|
16
|
+
|
|
17
|
+
## 🚀 Quick Start
|
|
18
|
+
|
|
19
|
+
### Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
# Install from NPM
|
|
23
|
+
npm install -g ccman
|
|
24
|
+
|
|
25
|
+
# Or install dependencies for development
|
|
26
|
+
npm install && npm run build
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Basic Usage
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
# Interactive setup (recommended)
|
|
33
|
+
ccman config
|
|
34
|
+
|
|
35
|
+
# Or add environment directly
|
|
36
|
+
ccman add default https://api.anthropic.com your-api-key
|
|
37
|
+
|
|
38
|
+
# List all environments
|
|
39
|
+
ccman ls
|
|
40
|
+
|
|
41
|
+
# Switch to an environment with source options
|
|
42
|
+
ccman use default
|
|
43
|
+
|
|
44
|
+
# Show current environment
|
|
45
|
+
ccman current
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## 📖 Commands Reference
|
|
49
|
+
|
|
50
|
+
### Core Environment Management
|
|
51
|
+
```bash
|
|
52
|
+
ccman add <name> <baseUrl> [apiKey] # Add environment (interactive API key if not provided)
|
|
53
|
+
ccman remove <name> # Remove environment group
|
|
54
|
+
ccman use <name> # Switch environment with source interaction
|
|
55
|
+
ccman list|ls # List all environments (* = current)
|
|
56
|
+
ccman current # Show current environment details
|
|
57
|
+
ccman clear|clearall # Clear ALL environments and shell integration (DESTRUCTIVE)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Interactive Configuration
|
|
61
|
+
```bash
|
|
62
|
+
ccman config # Full interactive configuration wizard
|
|
63
|
+
# - Add/switch/edit/remove environments
|
|
64
|
+
# - No existing environments? Guided setup
|
|
65
|
+
# - Complete menu-driven interface
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Advanced Operations
|
|
69
|
+
```bash
|
|
70
|
+
ccman status # Show detailed CCM statistics
|
|
71
|
+
ccman test [name] # Test environment configuration
|
|
72
|
+
ccman env # Generate shell export script
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Shell Integration Options
|
|
76
|
+
```bash
|
|
77
|
+
# Disable automatic shell writing
|
|
78
|
+
ccman add <name> <url> --no-auto-write
|
|
79
|
+
ccman use <name> --no-auto-write
|
|
80
|
+
|
|
81
|
+
# Force automatic source (risky)
|
|
82
|
+
ccman use <name> --auto-source
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## 🔧 Interactive Workflows
|
|
86
|
+
|
|
87
|
+
### 1. Adding Environment with Smart Use Flow
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
$ ccman add myenv https://api.example.com
|
|
91
|
+
? Enter API Key: ****************
|
|
92
|
+
✓ Added environment group "myenv"
|
|
93
|
+
Base URL: https://api.example.com
|
|
94
|
+
Created: 2025-08-06 11:45:30
|
|
95
|
+
|
|
96
|
+
? Set "myenv" as current environment? Yes
|
|
97
|
+
✓ Environment variables written to /home/user/.ccman/.ccmanrc
|
|
98
|
+
|
|
99
|
+
? How would you like to apply the environment variables?
|
|
100
|
+
❯ Manual - I will restart terminal or source manually (Recommended)
|
|
101
|
+
Auto-source - Try to source automatically (May not work in all environments)
|
|
102
|
+
|
|
103
|
+
> Manual
|
|
104
|
+
To apply changes, restart your terminal or run:
|
|
105
|
+
source ~/.bashrc (or ~/.zshrc)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### 2. Interactive Configuration Menu
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
$ ccman config
|
|
112
|
+
? What would you like to do?
|
|
113
|
+
❯ Switch environment
|
|
114
|
+
Add new environment
|
|
115
|
+
Edit environment
|
|
116
|
+
Remove environment
|
|
117
|
+
Show current status
|
|
118
|
+
|
|
119
|
+
> Add new environment
|
|
120
|
+
? Environment name: staging
|
|
121
|
+
? Base URL: https://staging-api.example.com
|
|
122
|
+
? API Key: ****************
|
|
123
|
+
✓ Added environment "staging"
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### 3. Environment Switching with Source Control
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
$ ccman use production
|
|
130
|
+
✓ Switched to environment "production"
|
|
131
|
+
Base URL: https://api.anthropic.com
|
|
132
|
+
✓ Environment variables written to /home/user/.ccman/.ccmanrc
|
|
133
|
+
|
|
134
|
+
? How would you like to apply the environment variables?
|
|
135
|
+
Manual - I will restart terminal or source manually (Recommended)
|
|
136
|
+
❯ Auto-source - Try to source automatically (May not work in all environments)
|
|
137
|
+
|
|
138
|
+
> Auto-source
|
|
139
|
+
⚠️ Attempting auto-source - this may not work in all terminal environments
|
|
140
|
+
✓ Shell configuration sourced successfully
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## 🛡️ Safe Shell Integration Architecture
|
|
144
|
+
|
|
145
|
+
### How It Works
|
|
146
|
+
|
|
147
|
+
CCM uses a **two-tier architecture** for safe shell integration:
|
|
148
|
+
|
|
149
|
+
1. **Independent Configuration File**: `~/.ccman/.ccmanrc`
|
|
150
|
+
```bash
|
|
151
|
+
# CCM (Claude Code Manager) Environment Variables - Auto Generated
|
|
152
|
+
# Generated at: 2025-08-06 11:45:30
|
|
153
|
+
# Environment: production
|
|
154
|
+
export ANTHROPIC_BASE_URL="https://api.anthropic.com"
|
|
155
|
+
export ANTHROPIC_AUTH_TOKEN="your-api-key"
|
|
156
|
+
# End CCM Environment Variables
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
2. **Minimal Shell Reference**: One line added to `.bashrc`/`.zshrc`
|
|
160
|
+
```bash
|
|
161
|
+
# CCM (Claude Code Manager) - Auto Generated Reference
|
|
162
|
+
[ -f "/home/user/.ccman/.ccmanrc" ] && source "/home/user/.ccman/.ccmanrc"
|
|
163
|
+
# End CCM Reference
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Benefits
|
|
167
|
+
- ✅ **Non-invasive**: Only adds one reference line to shell config
|
|
168
|
+
- ✅ **Safe**: User's existing shell config remains untouched
|
|
169
|
+
- ✅ **Clean**: Easy to remove completely
|
|
170
|
+
- ✅ **Isolated**: All CCM variables in separate file
|
|
171
|
+
|
|
172
|
+
### Environment Variables Managed
|
|
173
|
+
- `ANTHROPIC_BASE_URL` - API base URL
|
|
174
|
+
- `ANTHROPIC_AUTH_TOKEN` - API authentication token
|
|
175
|
+
|
|
176
|
+
## 📊 Configuration Structure
|
|
177
|
+
|
|
178
|
+
CCM stores configuration in `~/.ccman/config.json`:
|
|
179
|
+
|
|
180
|
+
```json
|
|
181
|
+
{
|
|
182
|
+
"current": "production",
|
|
183
|
+
"environments": {
|
|
184
|
+
"production": {
|
|
185
|
+
"name": "production",
|
|
186
|
+
"baseUrl": "https://api.anthropic.com",
|
|
187
|
+
"apiKey": "your-key",
|
|
188
|
+
"createdAt": "2025-08-06T03:45:30.000Z",
|
|
189
|
+
"lastUsed": "2025-08-06T03:50:15.000Z"
|
|
190
|
+
},
|
|
191
|
+
"staging": {
|
|
192
|
+
"name": "staging",
|
|
193
|
+
"baseUrl": "https://staging-api.example.com",
|
|
194
|
+
"apiKey": "staging-key",
|
|
195
|
+
"createdAt": "2025-08-06T03:46:00.000Z"
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
"settings": {
|
|
199
|
+
"autoWriteShell": true,
|
|
200
|
+
"preferredShell": "auto",
|
|
201
|
+
"shellConfigPath": null
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## 💡 Usage Examples
|
|
207
|
+
|
|
208
|
+
### Complete Setup Workflow
|
|
209
|
+
```bash
|
|
210
|
+
# Start with interactive setup
|
|
211
|
+
ccman config
|
|
212
|
+
# → Guided through adding first environment
|
|
213
|
+
# → Automatically prompted to set as current
|
|
214
|
+
# → Choose source method (manual/auto)
|
|
215
|
+
|
|
216
|
+
# Add more environments
|
|
217
|
+
ccman add staging https://staging.example.com
|
|
218
|
+
ccman add dev https://dev.example.com
|
|
219
|
+
|
|
220
|
+
# Switch with full interaction
|
|
221
|
+
ccman use dev
|
|
222
|
+
# → Writes to ~/.ccman/.ccmanrc
|
|
223
|
+
# → Asks about sourcing method
|
|
224
|
+
# → Provides clear instructions
|
|
225
|
+
|
|
226
|
+
# Check status
|
|
227
|
+
ccman status
|
|
228
|
+
# CCM Status:
|
|
229
|
+
# Total environments: 3
|
|
230
|
+
# Current environment: dev
|
|
231
|
+
# Shell integration: Enabled
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### Manual Environment Variable Setup
|
|
235
|
+
```bash
|
|
236
|
+
# If you prefer manual control
|
|
237
|
+
ccman use prod --no-auto-write
|
|
238
|
+
ccman env # Shows export script
|
|
239
|
+
source <(ccman env) # Apply manually
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### Advanced Usage
|
|
243
|
+
```bash
|
|
244
|
+
# Test environment connectivity
|
|
245
|
+
ccman test production
|
|
246
|
+
|
|
247
|
+
# Force auto-source (with risk warning)
|
|
248
|
+
ccman use staging --auto-source
|
|
249
|
+
|
|
250
|
+
# Edit existing environment
|
|
251
|
+
ccman config # → Edit environment → Select → Update values
|
|
252
|
+
|
|
253
|
+
# Complete reset (removes EVERYTHING - environments, shell config)
|
|
254
|
+
ccman clear # Interactive confirmation required
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
## ⚙️ Development
|
|
258
|
+
|
|
259
|
+
```bash
|
|
260
|
+
# Development mode (with file watching)
|
|
261
|
+
npm run dev
|
|
262
|
+
|
|
263
|
+
# Build TypeScript
|
|
264
|
+
npm run build
|
|
265
|
+
|
|
266
|
+
# Clean build artifacts
|
|
267
|
+
npm run clean
|
|
268
|
+
|
|
269
|
+
# Start built CLI
|
|
270
|
+
npm start
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
## 🎯 Command Line Options
|
|
274
|
+
|
|
275
|
+
### Global Options
|
|
276
|
+
All commands support standard CLI conventions:
|
|
277
|
+
- `-h, --help` - Show command help
|
|
278
|
+
- `-V, --version` - Show version
|
|
279
|
+
|
|
280
|
+
### Add Command Options
|
|
281
|
+
```bash
|
|
282
|
+
ccman add <name> <baseUrl> [apiKey] [options]
|
|
283
|
+
|
|
284
|
+
Options:
|
|
285
|
+
--no-auto-write Do not automatically write to shell config
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
### Use Command Options
|
|
289
|
+
```bash
|
|
290
|
+
ccman use <name> [options]
|
|
291
|
+
|
|
292
|
+
Options:
|
|
293
|
+
--no-auto-write Do not automatically write to shell config
|
|
294
|
+
--auto-source Automatically source shell config (risky)
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
## 🔍 Troubleshooting
|
|
298
|
+
|
|
299
|
+
### Environment Variables Not Applied
|
|
300
|
+
```bash
|
|
301
|
+
# Check if .ccmanrc exists
|
|
302
|
+
ls -la ~/.ccman/.ccmanrc
|
|
303
|
+
|
|
304
|
+
# Check shell reference
|
|
305
|
+
grep "ccman" ~/.bashrc ~/.zshrc
|
|
306
|
+
|
|
307
|
+
# Manual application
|
|
308
|
+
source ~/.ccman/.ccmanrc
|
|
309
|
+
|
|
310
|
+
# Or regenerate
|
|
311
|
+
ccman use <current-env>
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
### Shell Integration Issues
|
|
315
|
+
```bash
|
|
316
|
+
# Check shell type detection
|
|
317
|
+
ccman status
|
|
318
|
+
|
|
319
|
+
# Force manual setup
|
|
320
|
+
ccman use <env> --no-auto-write
|
|
321
|
+
source <(ccman env)
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
## 📋 Requirements
|
|
325
|
+
|
|
326
|
+
- Node.js >= 16.0.0
|
|
327
|
+
- TypeScript 5.0+
|
|
328
|
+
- Supported shells: bash, zsh, fish
|
|
329
|
+
- Operating systems: Linux, macOS, Windows (WSL)
|
|
330
|
+
|
|
331
|
+
## 📄 License
|
|
332
|
+
|
|
333
|
+
MIT License - see LICENSE file for details.
|
|
334
|
+
|
|
335
|
+
---
|
|
336
|
+
|
|
337
|
+
## 🚀 From Setup to Usage - Complete Flow
|
|
338
|
+
|
|
339
|
+
```bash
|
|
340
|
+
# 1. Interactive first-time setup
|
|
341
|
+
ccman config
|
|
342
|
+
→ No environments? Guided creation
|
|
343
|
+
→ Set as current? Yes
|
|
344
|
+
→ Source method? Manual/Auto
|
|
345
|
+
|
|
346
|
+
# 2. Add more environments
|
|
347
|
+
ccman add dev https://dev.api.com
|
|
348
|
+
→ Interactive API key input
|
|
349
|
+
→ Set as current? Yes/No
|
|
350
|
+
→ Full source interaction if Yes
|
|
351
|
+
|
|
352
|
+
# 3. Switch anytime with full control
|
|
353
|
+
ccman use production
|
|
354
|
+
→ Safe .ccmanrc update
|
|
355
|
+
→ Source method choice
|
|
356
|
+
→ Clear instructions
|
|
357
|
+
|
|
358
|
+
# 4. Everything just works! ✨
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
*CCM - Making Claude Code API configuration management safe, interactive, and user-friendly.*
|
package/README_zh.md
ADDED
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
# CCM - Claude Code Manager
|
|
2
|
+
|
|
3
|
+
基于 TypeScript 的命令行工具,通过**独立配置文件进行安全的 Shell 集成**,管理 Claude Code API 配置。
|
|
4
|
+
|
|
5
|
+
> [English Documentation](./README.md) | **中文文档**
|
|
6
|
+
|
|
7
|
+
## ✨ 特性
|
|
8
|
+
|
|
9
|
+
✅ **环境组管理** - 添加、删除、切换 Claude Code 环境
|
|
10
|
+
✅ **安全的 Shell 集成** - 使用独立的 `~/.ccman/.ccmanrc` 文件避免修改用户配置
|
|
11
|
+
✅ **交互式 Source 控制** - 选择手动或自动 source,附带风险警告
|
|
12
|
+
✅ **类型安全** - 完整的 TypeScript 实现,严格类型检查
|
|
13
|
+
✅ **交互式 CLI** - 用户友好的命令,彩色输出和 inquirer 提示
|
|
14
|
+
✅ **多 Shell 支持** - 支持 bash、zsh 和 fish
|
|
15
|
+
✅ **完整工作流** - 从设置到使用的无缝流程
|
|
16
|
+
|
|
17
|
+
## 🚀 快速开始
|
|
18
|
+
|
|
19
|
+
### 安装
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
# 从 NPM 安装
|
|
23
|
+
npm install -g ccman
|
|
24
|
+
|
|
25
|
+
# 或者开发环境安装依赖
|
|
26
|
+
npm install && npm run build
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### 基本用法
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
# 交互式设置(推荐)
|
|
33
|
+
ccman config
|
|
34
|
+
|
|
35
|
+
# 或直接添加环境
|
|
36
|
+
ccman add default https://api.anthropic.com your-api-key
|
|
37
|
+
|
|
38
|
+
# 列出所有环境
|
|
39
|
+
ccman ls
|
|
40
|
+
|
|
41
|
+
# 切换环境(支持 source 选项)
|
|
42
|
+
ccman use default
|
|
43
|
+
|
|
44
|
+
# 显示当前环境
|
|
45
|
+
ccman current
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## 📖 命令参考
|
|
49
|
+
|
|
50
|
+
### 核心环境管理
|
|
51
|
+
```bash
|
|
52
|
+
ccman add <name> <baseUrl> [apiKey] # 添加环境(未提供 API key 时交互输入)
|
|
53
|
+
ccman remove <name> # 删除环境组
|
|
54
|
+
ccman use <name> # 切换环境(支持 source 交互)
|
|
55
|
+
ccman list|ls # 列出所有环境(* = 当前环境)
|
|
56
|
+
ccman current # 显示当前环境详情
|
|
57
|
+
ccman clear|clearall # 清除所有环境和 Shell 集成(危险操作)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### 交互式配置
|
|
61
|
+
```bash
|
|
62
|
+
ccman config # 完整交互式配置向导
|
|
63
|
+
# - 添加/切换/编辑/删除环境
|
|
64
|
+
# - 无环境时引导设置
|
|
65
|
+
# - 完整菜单驱动界面
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### 高级操作
|
|
69
|
+
```bash
|
|
70
|
+
ccman status # 显示详细 CCM 统计信息
|
|
71
|
+
ccman test [name] # 测试环境配置
|
|
72
|
+
ccman env # 生成 shell 导出脚本
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Shell 集成选项
|
|
76
|
+
```bash
|
|
77
|
+
# 禁用自动 shell 写入
|
|
78
|
+
ccman add <name> <url> --no-auto-write
|
|
79
|
+
ccman use <name> --no-auto-write
|
|
80
|
+
|
|
81
|
+
# 强制自动 source(有风险)
|
|
82
|
+
ccman use <name> --auto-source
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## 🔧 交互式工作流
|
|
86
|
+
|
|
87
|
+
### 1. 添加环境的智能使用流程
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
$ ccman add myenv https://api.example.com
|
|
91
|
+
? 输入 API Key: ****************
|
|
92
|
+
✓ 已添加环境组 "myenv"
|
|
93
|
+
Base URL: https://api.example.com
|
|
94
|
+
创建时间: 2025-08-06 11:45:30
|
|
95
|
+
|
|
96
|
+
? 将 "myenv" 设为当前环境? 是
|
|
97
|
+
✓ 环境变量已写入 /home/user/.ccman/.ccmanrc
|
|
98
|
+
|
|
99
|
+
? 如何应用环境变量?
|
|
100
|
+
❯ 手动 - 我将重启终端或手动 source(推荐)
|
|
101
|
+
自动 source - 尝试自动 source(可能在某些环境下不工作)
|
|
102
|
+
|
|
103
|
+
> 手动
|
|
104
|
+
要应用更改,请重启终端或运行:
|
|
105
|
+
source ~/.bashrc (或 ~/.zshrc)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### 2. 交互式配置菜单
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
$ ccman config
|
|
112
|
+
? 你想做什么?
|
|
113
|
+
❯ 切换环境
|
|
114
|
+
添加新环境
|
|
115
|
+
编辑环境
|
|
116
|
+
删除环境
|
|
117
|
+
显示当前状态
|
|
118
|
+
|
|
119
|
+
> 添加新环境
|
|
120
|
+
? 环境名称: staging
|
|
121
|
+
? Base URL: https://staging-api.example.com
|
|
122
|
+
? API Key: ****************
|
|
123
|
+
✓ 已添加环境 "staging"
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### 3. 环境切换与 Source 控制
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
$ ccman use production
|
|
130
|
+
✓ 已切换到环境 "production"
|
|
131
|
+
Base URL: https://api.anthropic.com
|
|
132
|
+
✓ 环境变量已写入 /home/user/.ccman/.ccmanrc
|
|
133
|
+
|
|
134
|
+
? 如何应用环境变量?
|
|
135
|
+
手动 - 我将重启终端或手动 source(推荐)
|
|
136
|
+
❯ 自动 source - 尝试自动 source(可能在某些环境下不工作)
|
|
137
|
+
|
|
138
|
+
> 自动 source
|
|
139
|
+
⚠️ 尝试自动 source - 这可能在某些终端环境下不工作
|
|
140
|
+
✓ Shell 配置已成功 source
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## 🛡️ 安全的 Shell 集成架构
|
|
144
|
+
|
|
145
|
+
### 工作原理
|
|
146
|
+
|
|
147
|
+
CCM 使用**双层架构**进行安全的 shell 集成:
|
|
148
|
+
|
|
149
|
+
1. **独立配置文件**:`~/.ccman/.ccmanrc`
|
|
150
|
+
```bash
|
|
151
|
+
# CCM (Claude Code Manager) Environment Variables - Auto Generated
|
|
152
|
+
# Generated at: 2025-08-06 11:45:30
|
|
153
|
+
# Environment: production
|
|
154
|
+
export ANTHROPIC_BASE_URL="https://api.anthropic.com"
|
|
155
|
+
export ANTHROPIC_AUTH_TOKEN="your-api-key"
|
|
156
|
+
# End CCM Environment Variables
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
2. **最小 Shell 引用**:在 `.bashrc`/`.zshrc` 中添加一行引用
|
|
160
|
+
```bash
|
|
161
|
+
# CCM (Claude Code Manager) - Auto Generated Reference
|
|
162
|
+
[ -f "/home/user/.ccman/.ccmanrc" ] && source "/home/user/.ccman/.ccmanrc"
|
|
163
|
+
# End CCM Reference
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### 优势
|
|
167
|
+
- ✅ **非侵入性**:只在 shell 配置中添加一行引用
|
|
168
|
+
- ✅ **安全**:用户现有的 shell 配置保持不变
|
|
169
|
+
- ✅ **清洁**:易于完全移除
|
|
170
|
+
- ✅ **隔离**:所有 CCM 变量在单独文件中
|
|
171
|
+
|
|
172
|
+
### 管理的环境变量
|
|
173
|
+
- `ANTHROPIC_BASE_URL` - API 基础 URL
|
|
174
|
+
- `ANTHROPIC_AUTH_TOKEN` - API 认证令牌
|
|
175
|
+
|
|
176
|
+
## 📊 配置结构
|
|
177
|
+
|
|
178
|
+
CCM 在 `~/.ccman/config.json` 中存储配置:
|
|
179
|
+
|
|
180
|
+
```json
|
|
181
|
+
{
|
|
182
|
+
"current": "production",
|
|
183
|
+
"environments": {
|
|
184
|
+
"production": {
|
|
185
|
+
"name": "production",
|
|
186
|
+
"baseUrl": "https://api.anthropic.com",
|
|
187
|
+
"apiKey": "your-key",
|
|
188
|
+
"createdAt": "2025-08-06T03:45:30.000Z",
|
|
189
|
+
"lastUsed": "2025-08-06T03:50:15.000Z"
|
|
190
|
+
},
|
|
191
|
+
"staging": {
|
|
192
|
+
"name": "staging",
|
|
193
|
+
"baseUrl": "https://staging-api.example.com",
|
|
194
|
+
"apiKey": "staging-key",
|
|
195
|
+
"createdAt": "2025-08-06T03:46:00.000Z"
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
"settings": {
|
|
199
|
+
"autoWriteShell": true,
|
|
200
|
+
"preferredShell": "auto",
|
|
201
|
+
"shellConfigPath": null
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## 💡 使用示例
|
|
207
|
+
|
|
208
|
+
### 完整设置工作流
|
|
209
|
+
```bash
|
|
210
|
+
# 从交互式设置开始
|
|
211
|
+
ccman config
|
|
212
|
+
# → 引导添加第一个环境
|
|
213
|
+
# → 自动提示设为当前环境
|
|
214
|
+
# → 选择 source 方法(手动/自动)
|
|
215
|
+
|
|
216
|
+
# 添加更多环境
|
|
217
|
+
ccman add staging https://staging.example.com
|
|
218
|
+
ccman add dev https://dev.example.com
|
|
219
|
+
|
|
220
|
+
# 完整交互切换
|
|
221
|
+
ccman use dev
|
|
222
|
+
# → 写入到 ~/.ccman/.ccmanrc
|
|
223
|
+
# → 询问 source 方法
|
|
224
|
+
# → 提供清晰指导
|
|
225
|
+
|
|
226
|
+
# 检查状态
|
|
227
|
+
ccman status
|
|
228
|
+
# CCM 状态:
|
|
229
|
+
# 总环境数: 3
|
|
230
|
+
# 当前环境: dev
|
|
231
|
+
# Shell 集成: 已启用
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### 手动环境变量设置
|
|
235
|
+
```bash
|
|
236
|
+
# 如果你偏好手动控制
|
|
237
|
+
ccman use prod --no-auto-write
|
|
238
|
+
ccman env # 显示导出脚本
|
|
239
|
+
source <(ccman env) # 手动应用
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### 高级用法
|
|
243
|
+
```bash
|
|
244
|
+
# 测试环境连接性
|
|
245
|
+
ccman test production
|
|
246
|
+
|
|
247
|
+
# 强制自动 source(有风险警告)
|
|
248
|
+
ccman use staging --auto-source
|
|
249
|
+
|
|
250
|
+
# 编辑现有环境
|
|
251
|
+
ccman config # → 编辑环境 → 选择 → 更新值
|
|
252
|
+
|
|
253
|
+
# 完全重置(删除所有内容 - 环境、shell 配置)
|
|
254
|
+
ccman clear # 需要交互确认
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
## ⚙️ 开发
|
|
258
|
+
|
|
259
|
+
```bash
|
|
260
|
+
# 开发模式(文件监听)
|
|
261
|
+
npm run dev
|
|
262
|
+
|
|
263
|
+
# 构建 TypeScript
|
|
264
|
+
npm run build
|
|
265
|
+
|
|
266
|
+
# 清理构建产物
|
|
267
|
+
npm run clean
|
|
268
|
+
|
|
269
|
+
# 运行构建后的 CLI
|
|
270
|
+
npm start
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
## 🎯 命令行选项
|
|
274
|
+
|
|
275
|
+
### 全局选项
|
|
276
|
+
所有命令都支持标准 CLI 约定:
|
|
277
|
+
- `-h, --help` - 显示命令帮助
|
|
278
|
+
- `-V, --version` - 显示版本
|
|
279
|
+
|
|
280
|
+
### Add 命令选项
|
|
281
|
+
```bash
|
|
282
|
+
ccman add <name> <baseUrl> [apiKey] [选项]
|
|
283
|
+
|
|
284
|
+
选项:
|
|
285
|
+
--no-auto-write 不自动写入 shell 配置
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
### Use 命令选项
|
|
289
|
+
```bash
|
|
290
|
+
ccman use <name> [选项]
|
|
291
|
+
|
|
292
|
+
选项:
|
|
293
|
+
--no-auto-write 不自动写入 shell 配置
|
|
294
|
+
--auto-source 自动 source shell 配置(有风险)
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
## 🔍 故障排除
|
|
298
|
+
|
|
299
|
+
### 环境变量未应用
|
|
300
|
+
```bash
|
|
301
|
+
# 检查 .ccmanrc 是否存在
|
|
302
|
+
ls -la ~/.ccman/.ccmanrc
|
|
303
|
+
|
|
304
|
+
# 检查 shell 引用
|
|
305
|
+
grep "ccman" ~/.bashrc ~/.zshrc
|
|
306
|
+
|
|
307
|
+
# 手动应用
|
|
308
|
+
source ~/.ccman/.ccmanrc
|
|
309
|
+
|
|
310
|
+
# 或重新生成
|
|
311
|
+
ccman use <当前环境>
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
### Shell 集成问题
|
|
315
|
+
```bash
|
|
316
|
+
# 检查 shell 类型检测
|
|
317
|
+
ccman status
|
|
318
|
+
|
|
319
|
+
# 强制手动设置
|
|
320
|
+
ccman use <环境> --no-auto-write
|
|
321
|
+
source <(ccman env)
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
## 📋 要求
|
|
325
|
+
|
|
326
|
+
- Node.js >= 16.0.0
|
|
327
|
+
- TypeScript 5.0+
|
|
328
|
+
- 支持的 shell: bash, zsh, fish
|
|
329
|
+
- 操作系统: Linux, macOS, Windows (WSL)
|
|
330
|
+
|
|
331
|
+
## 📄 许可证
|
|
332
|
+
|
|
333
|
+
MIT 许可证 - 详见 LICENSE 文件。
|
|
334
|
+
|
|
335
|
+
---
|
|
336
|
+
|
|
337
|
+
## 🚀 从设置到使用 - 完整流程
|
|
338
|
+
|
|
339
|
+
```bash
|
|
340
|
+
# 1. 交互式首次设置
|
|
341
|
+
ccman config
|
|
342
|
+
→ 无环境?引导创建
|
|
343
|
+
→ 设为当前环境?是
|
|
344
|
+
→ Source 方法?手动/自动
|
|
345
|
+
|
|
346
|
+
# 2. 添加更多环境
|
|
347
|
+
ccman add dev https://dev.api.com
|
|
348
|
+
→ 交互式 API key 输入
|
|
349
|
+
→ 设为当前环境?是/否
|
|
350
|
+
→ 如选是则完整 source 交互
|
|
351
|
+
|
|
352
|
+
# 3. 随时切换,完全控制
|
|
353
|
+
ccman use production
|
|
354
|
+
→ 安全 .ccmanrc 更新
|
|
355
|
+
→ Source 方法选择
|
|
356
|
+
→ 清晰指导
|
|
357
|
+
|
|
358
|
+
# 4. 一切正常工作! ✨
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
*CCM - 让 Claude Code API 配置管理变得安全、交互式且用户友好。*
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|