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.
Files changed (58) hide show
  1. package/.editorconfig +15 -0
  2. package/.eslintrc.js +28 -0
  3. package/.github/workflows/release.yml +213 -0
  4. package/.prettierrc +10 -0
  5. package/CLAUDE.md +215 -0
  6. package/README.md +361 -0
  7. package/README_zh.md +361 -0
  8. package/dist/cli.d.ts +3 -0
  9. package/dist/cli.d.ts.map +1 -0
  10. package/dist/cli.js +476 -0
  11. package/dist/cli.js.map +1 -0
  12. package/dist/config/ConfigManager.d.ts +67 -0
  13. package/dist/config/ConfigManager.d.ts.map +1 -0
  14. package/dist/config/ConfigManager.js +226 -0
  15. package/dist/config/ConfigManager.js.map +1 -0
  16. package/dist/config/EnvironmentManager.d.ts +83 -0
  17. package/dist/config/EnvironmentManager.d.ts.map +1 -0
  18. package/dist/config/EnvironmentManager.js +280 -0
  19. package/dist/config/EnvironmentManager.js.map +1 -0
  20. package/dist/config/constants.d.ts +40 -0
  21. package/dist/config/constants.d.ts.map +1 -0
  22. package/dist/config/constants.js +97 -0
  23. package/dist/config/constants.js.map +1 -0
  24. package/dist/index.d.ts +5 -0
  25. package/dist/index.d.ts.map +1 -0
  26. package/dist/index.js +26 -0
  27. package/dist/index.js.map +1 -0
  28. package/dist/shell/ShellManager.d.ts +73 -0
  29. package/dist/shell/ShellManager.d.ts.map +1 -0
  30. package/dist/shell/ShellManager.js +391 -0
  31. package/dist/shell/ShellManager.js.map +1 -0
  32. package/dist/types/index.d.ts +55 -0
  33. package/dist/types/index.d.ts.map +1 -0
  34. package/dist/types/index.js +6 -0
  35. package/dist/types/index.js.map +1 -0
  36. package/dist/utils/version.d.ts +67 -0
  37. package/dist/utils/version.d.ts.map +1 -0
  38. package/dist/utils/version.js +199 -0
  39. package/dist/utils/version.js.map +1 -0
  40. package/docs/npm-publish-guide.md +71 -0
  41. package/docs/release-guide.md +86 -0
  42. package/docs/version-management.md +64 -0
  43. package/jest.config.js +22 -0
  44. package/package.json +57 -0
  45. package/release-temp/README.md +361 -0
  46. package/release-temp/package.json +57 -0
  47. package/scripts/publish-local.sh +91 -0
  48. package/scripts/quick-release.sh +100 -0
  49. package/scripts/release.sh +430 -0
  50. package/src/cli.ts +510 -0
  51. package/src/config/ConfigManager.ts +227 -0
  52. package/src/config/EnvironmentManager.ts +327 -0
  53. package/src/config/constants.ts +64 -0
  54. package/src/index.ts +5 -0
  55. package/src/shell/ShellManager.ts +416 -0
  56. package/src/types/index.ts +60 -0
  57. package/src/utils/version.ts +189 -0
  58. package/tsconfig.json +25 -0
package/.editorconfig ADDED
@@ -0,0 +1,15 @@
1
+ root = true
2
+
3
+ [*]
4
+ charset = utf-8
5
+ end_of_line = lf
6
+ indent_style = space
7
+ indent_size = 2
8
+ insert_final_newline = true
9
+ trim_trailing_whitespace = true
10
+
11
+ [*.md]
12
+ trim_trailing_whitespace = false
13
+
14
+ [{package.json,*.yml,*.yaml}]
15
+ indent_size = 2
package/.eslintrc.js ADDED
@@ -0,0 +1,28 @@
1
+ module.exports = {
2
+ root: true,
3
+ parser: '@typescript-eslint/parser',
4
+ plugins: ['@typescript-eslint'],
5
+ extends: [
6
+ 'eslint:recommended'
7
+ ],
8
+ parserOptions: {
9
+ ecmaVersion: 2020,
10
+ sourceType: 'module'
11
+ },
12
+ env: {
13
+ node: true,
14
+ es2020: true,
15
+ },
16
+ rules: {
17
+ // 基本规则
18
+ 'no-unused-vars': 'off',
19
+ '@typescript-eslint/no-unused-vars': 'error',
20
+ 'no-console': 'off', // CLI工具需要console输出
21
+ 'no-process-exit': 'off', // CLI工具需要process.exit
22
+ },
23
+ ignorePatterns: [
24
+ 'dist/',
25
+ 'node_modules/',
26
+ '*.js', // 忽略根目录的JS配置文件
27
+ ],
28
+ };
@@ -0,0 +1,213 @@
1
+ name: Release and Publish
2
+
3
+ # 触发条件:推送 tag 或手动触发
4
+ on:
5
+ push:
6
+ tags:
7
+ - 'v*.*.*' # 匹配语义化版本标签 (v1.0.0, v1.2.3, etc.)
8
+ workflow_dispatch: # 支持手动触发
9
+ inputs:
10
+ version:
11
+ description: 'Release version (e.g., 1.0.0)'
12
+ required: true
13
+ default: 'patch'
14
+ type: choice
15
+ options:
16
+ - patch
17
+ - minor
18
+ - major
19
+
20
+ jobs:
21
+ release:
22
+ name: Release and Publish to NPM
23
+ runs-on: ubuntu-latest
24
+
25
+ permissions:
26
+ contents: write # 需要写入权限来创建 release
27
+ id-token: write # NPM 发布需要
28
+
29
+ steps:
30
+ # 1. 检出代码
31
+ - name: Checkout code
32
+ uses: actions/checkout@v4
33
+ with:
34
+ fetch-depth: 0 # 获取完整历史记录用于生成 changelog
35
+
36
+ # 2. 设置 pnpm
37
+ - name: Setup pnpm
38
+ uses: pnpm/action-setup@v4
39
+ with:
40
+ version: 8.15.1 # 固定版本保证稳定性
41
+
42
+ # 3. 设置 Node.js 和缓存
43
+ - name: Setup Node.js
44
+ uses: actions/setup-node@v4
45
+ with:
46
+ node-version: '18'
47
+ cache: 'pnpm'
48
+
49
+ # 4. 安装依赖
50
+ - name: Install dependencies
51
+ run: pnpm install
52
+
53
+ # 5. 运行测试和代码检查
54
+ - name: Run tests and linting
55
+ run: |
56
+ pnpm run lint
57
+ pnpm run build
58
+ continue-on-error: false
59
+
60
+ # 6. 获取版本信息
61
+ - name: Get version info
62
+ id: version
63
+ run: |
64
+ if [ "${{ github.event_name }}" == "push" ]; then
65
+ # 从 tag 中提取版本
66
+ VERSION=${GITHUB_REF#refs/tags/v}
67
+ echo "version=$VERSION" >> $GITHUB_OUTPUT
68
+ echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
69
+ else
70
+ # 手动触发时使用输入的版本
71
+ VERSION=$(npm version ${{ github.event.inputs.version }} --no-git-tag-version --preid=beta)
72
+ VERSION=${VERSION#v}
73
+ echo "version=$VERSION" >> $GITHUB_OUTPUT
74
+ echo "tag=v$VERSION" >> $GITHUB_OUTPUT
75
+ fi
76
+ echo "package_version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
77
+
78
+ # 7. 验证版本一致性(仅对 tag 触发的构建)
79
+ - name: Validate version consistency
80
+ if: github.event_name == 'push'
81
+ run: |
82
+ PACKAGE_VERSION=$(node -p "require('./package.json').version")
83
+ TAG_VERSION="${{ steps.version.outputs.version }}"
84
+ if [ "$PACKAGE_VERSION" != "$TAG_VERSION" ]; then
85
+ echo "❌ Version mismatch: package.json($PACKAGE_VERSION) != tag($TAG_VERSION)"
86
+ exit 1
87
+ fi
88
+ echo "✅ Version validation passed: $PACKAGE_VERSION"
89
+
90
+ # 8. 生成构建产物
91
+ - name: Build project
92
+ run: |
93
+ pnpm run clean
94
+ pnpm run build
95
+
96
+ # 9. 创建发布包
97
+ - name: Create release archive
98
+ run: |
99
+ # 创建临时目录用于打包
100
+ mkdir -p release-temp
101
+
102
+ # 复制必要文件到临时目录
103
+ cp -r dist release-temp/
104
+ cp package.json release-temp/
105
+ cp README.md release-temp/
106
+ cp LICENSE release-temp/ 2>/dev/null || echo "No LICENSE file found"
107
+
108
+ # 创建压缩包
109
+ cd release-temp
110
+ tar -czf ../ccm-v${{ steps.version.outputs.version }}.tar.gz .
111
+ cd ..
112
+
113
+ echo "✅ Release archive created: ccm-v${{ steps.version.outputs.version }}.tar.gz"
114
+
115
+ # 10. 配置 NPM 认证
116
+ - name: Configure NPM authentication
117
+ run: |
118
+ echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" >> ~/.npmrc
119
+ ls -la ~/
120
+ echo "NPM configuration:"
121
+ cat ~/.npmrc
122
+
123
+ # 11. 验证 NPM 认证
124
+ - name: Verify NPM authentication
125
+ run: |
126
+ npm whoami
127
+ echo "✅ NPM authentication verified"
128
+
129
+ # 12. 发布到 NPM(使用 npm 确保兼容性)
130
+ - name: Publish to NPM
131
+ run: |
132
+ echo "Publishing to NPM..."
133
+
134
+ # 检查是否为预发布版本
135
+ VERSION="${{ steps.version.outputs.version }}"
136
+ if [[ "$VERSION" =~ -beta\.|alpha\.|rc\. ]]; then
137
+ echo "📦 Publishing pre-release version $VERSION with 'beta' tag"
138
+ npm publish --tag beta --access public
139
+ else
140
+ echo "📦 Publishing stable version $VERSION"
141
+ npm publish --access public
142
+ fi
143
+
144
+ echo "✅ Published to NPM successfully"
145
+
146
+ # 13. 创建 GitHub Release
147
+ - name: Create GitHub Release
148
+ uses: actions/create-release@v1
149
+ env:
150
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
151
+ with:
152
+ tag_name: ${{ steps.version.outputs.tag }}
153
+ release_name: "CCM v${{ steps.version.outputs.version }}"
154
+ body: |
155
+ ## CCM (Claude Code Manager) v${{ steps.version.outputs.version }}
156
+
157
+ 🚀 **新版本发布!**
158
+
159
+ ### 📦 安装方式
160
+ ```bash
161
+ npm install -g ccm@${{ steps.version.outputs.version }}
162
+ ```
163
+
164
+ ### 🔗 相关链接
165
+ - [NPM 包](https://www.npmjs.com/package/ccm)
166
+ - [GitHub 仓库](https://github.com/2ue/ccm)
167
+ - [中文文档](./README_zh.md)
168
+
169
+ ### 📋 发布信息
170
+ - **发布时间**: ${{ github.event.head_commit.timestamp }}
171
+ - **提交哈希**: ${{ github.sha }}
172
+ - **构建环境**: GitHub Actions (ubuntu-latest)
173
+
174
+ ---
175
+
176
+ *该版本通过 GitHub Actions 自动构建和发布*
177
+ draft: false
178
+ prerelease: ${{ contains(steps.version.outputs.version, 'beta') || contains(steps.version.outputs.version, 'alpha') || contains(steps.version.outputs.version, 'rc') }}
179
+
180
+ # 14. 上传发布文件到 Release
181
+ - name: Upload release assets
182
+ uses: actions/upload-release-asset@v1
183
+ env:
184
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
185
+ with:
186
+ upload_url: ${{ steps.create_release.outputs.upload_url }}
187
+ asset_path: ./ccm-v${{ steps.version.outputs.version }}.tar.gz
188
+ asset_name: ccm-v${{ steps.version.outputs.version }}.tar.gz
189
+ asset_content_type: application/gzip
190
+
191
+ # 15. 发布结果通知
192
+ - name: Release Summary
193
+ run: |
194
+ echo "## 🎉 发布成功 v${{ steps.version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
195
+ echo "" >> $GITHUB_STEP_SUMMARY
196
+ echo "### 📋 发布详情" >> $GITHUB_STEP_SUMMARY
197
+ echo "- **版本**: ${{ steps.version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
198
+ echo "- **NPM**: https://www.npmjs.com/package/ccm/v/${{ steps.version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
199
+ echo "- **GitHub Release**: ${{ github.server_url }}/${{ github.repository }}/releases/tag/${{ steps.version.outputs.tag }}" >> $GITHUB_STEP_SUMMARY
200
+ echo "- **安装命令**: \`npm install -g ccm@${{ steps.version.outputs.version }}\`" >> $GITHUB_STEP_SUMMARY
201
+
202
+ # 可选:部署文档或通知其他系统
203
+ post-release:
204
+ name: Post-release tasks
205
+ needs: release
206
+ runs-on: ubuntu-latest
207
+ if: always()
208
+
209
+ steps:
210
+ - name: Post-release cleanup
211
+ run: |
212
+ echo "✅ Release workflow completed"
213
+ echo "Version ${{ needs.release.outputs.version }} has been published"
package/.prettierrc ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "semi": true,
3
+ "trailingComma": "es5",
4
+ "singleQuote": true,
5
+ "printWidth": 80,
6
+ "tabWidth": 2,
7
+ "useTabs": false,
8
+ "endOfLine": "lf",
9
+ "arrowParens": "avoid"
10
+ }
package/CLAUDE.md ADDED
@@ -0,0 +1,215 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Project Overview
6
+
7
+ CCM (Claude Code Manager) is a TypeScript-based command-line tool for managing Claude Code API configurations. It provides structured, modular environment management with **safe shell integration** through independent configuration files.
8
+
9
+ ## Architecture
10
+
11
+ ### Core Modules
12
+ - **src/types/index.ts**: TypeScript type definitions for all interfaces
13
+ - **src/config/ConfigManager.ts**: Core configuration management with JSON storage
14
+ - **src/config/EnvironmentManager.ts**: High-level environment group operations
15
+ - **src/shell/ShellManager.ts**: Safe shell configuration file management using ..ccmanrc approach
16
+ - **src/cli.ts**: Command-line interface with Commander.js and unified interaction logic
17
+
18
+ ### Project Structure
19
+ ```
20
+ src/
21
+ ├── types/ # TypeScript type definitions
22
+ ├── config/ # Configuration management modules
23
+ ├── shell/ # Shell integration modules
24
+ ├── utils/ # Utility functions (future)
25
+ ├── cli.ts # CLI entry point with performUseEnvironment() shared function
26
+ └── index.ts # Module exports
27
+ ```
28
+
29
+ ## Key Features Implemented
30
+
31
+ ### 1. Safe Shell Integration Architecture
32
+ - **Independent .ccmanrc file**: `~/.ccman/.ccmanrc` contains all environment variables
33
+ - **Minimal shell reference**: Single line added to `.bashrc`/`.zshrc` to source .ccmanrc
34
+ - **Non-invasive approach**: User's shell config remains largely untouched
35
+ - **Easy cleanup**: Remove reference line and delete .ccmanrc file
36
+
37
+ ### 2. Interactive Source Control
38
+ - After environment switching, user chooses source method:
39
+ - **Manual**: User manually sources or restarts terminal (recommended)
40
+ - **Auto-source**: Tool attempts automatic sourcing with risk warnings
41
+
42
+ ### 3. Unified Use Logic
43
+ - `performUseEnvironment()` function provides consistent behavior across:
44
+ - `add` command's "set as current" flow
45
+ - Standalone `use` command
46
+ - `config` command's switch environment option
47
+
48
+ ### 4. Complete Interactive Workflows
49
+ - **config command**: Full menu-driven interface for all operations
50
+ - **add command**: Interactive API key input + use confirmation + source choice
51
+ - **Consistent interactions**: All use operations have identical user experience
52
+
53
+ ## Current Environment Variables
54
+
55
+ The tool manages these Claude Code environment variables:
56
+ - `ANTHROPIC_BASE_URL`: API base URL
57
+ - `ANTHROPIC_AUTH_TOKEN`: API authentication token
58
+
59
+ *Note: Updated from previous CLAUDE_API_BASE_URL and ANTHROPIC_API_KEY*
60
+
61
+ ## Common Commands
62
+
63
+ ### Development
64
+ ```bash
65
+ npm run build # Compile TypeScript to dist/
66
+ npm run dev # Run CLI in development mode with tsx
67
+ npm start # Run compiled CLI
68
+ npm run clean # Remove dist/ directory
69
+ npm run lint # Run ESLint on TypeScript files (requires config)
70
+ ```
71
+
72
+ ### Basic Usage
73
+ ```bash
74
+ ccman ls # List all environment groups (* = current)
75
+ ccman add <name> <url> # Add environment group with interactive flow
76
+ ccman use <name> # Switch environment with source interaction
77
+ ccman remove <name> # Delete environment group
78
+ ccman current # Show current environment
79
+ ccman status # Show CCM statistics
80
+ ccman config # Interactive configuration menu
81
+ ccman clear # Clear all environments and shell integration (DESTRUCTIVE)
82
+ ```
83
+
84
+ ### Advanced Features
85
+ ```bash
86
+ ccman env # Generate shell script for manual sourcing
87
+ ccman test [name] # Test environment configuration
88
+ ccman add <name> <url> --no-auto-write # Add without shell integration
89
+ ccman use <name> --no-auto-write # Switch without shell integration
90
+ ccman use <name> --auto-source # Force auto-source with risk warning
91
+ ```
92
+
93
+ ## Implementation Details
94
+
95
+ ### 1. Environment Group Management
96
+ - Add/remove/switch between environment groups
97
+ - Each group contains: name, baseUrl, apiKey, timestamps
98
+ - Automatic validation of URLs and required fields
99
+ - Interactive API key input if not provided
100
+
101
+ ### 2. Shell Integration Process
102
+ 1. **Write .ccmanrc**: Environment variables written to `~/.ccman/.ccmanrc`
103
+ 2. **Add reference**: Shell config updated to source .ccmanrc if not already present
104
+ 3. **User choice**: Interactive prompt for sourcing method
105
+ 4. **Auto-source**: Optional automatic sourcing with error handling
106
+
107
+ ### 3. Type Safety Implementation
108
+ - Full TypeScript implementation with strict typing
109
+ - Interfaces for all data structures and operations:
110
+ - `ClaudeEnv`: Environment configuration
111
+ - `ShellEnvVars`: Environment variables with correct naming
112
+ - `AddEnvOptions`: Add operation parameters
113
+ - `ShellWriteResult`: Shell operation results
114
+ - Compile-time error checking
115
+
116
+ ### 4. Interactive CLI Features
117
+ - Inquirer.js for consistent prompts
118
+ - Colored output with chalk
119
+ - Confirmation prompts for destructive operations
120
+ - Menu-driven configuration interface
121
+ - Progress feedback and error handling
122
+
123
+ ## Configuration Storage
124
+
125
+ - Config directory: `~/.ccman/`
126
+ - Main config: `~/.ccman/config.json`
127
+ - Environment variables: `~/.ccman/.ccmanrc`
128
+ - Structure includes environments, current selection, and global settings
129
+
130
+ ## Shell Integration Technical Details
131
+
132
+ ### File Locations
133
+ - **Configuration**: `~/.ccman/.ccmanrc` - Contains current environment variables
134
+ - **Shell reference**: Added to `.bashrc`, `.zshrc`, or `config.fish`
135
+ - **Detection order**: zsh → bash → fish → fallback
136
+
137
+ ### Shell Reference Format
138
+ ```bash
139
+ # CCM (Claude Code Manager) - Auto Generated Reference
140
+ # This line sources CCM environment variables from /home/user/.ccman/.ccmanrc
141
+ [ -f "/home/user/.ccman/.ccmanrc" ] && source "/home/user/.ccman/.ccmanrc"
142
+ # End CCM Reference
143
+ ```
144
+
145
+ ### .ccmanrc File Format
146
+ ```bash
147
+ # CCM (Claude Code Manager) Environment Variables - Auto Generated
148
+ # Generated at: 2025-08-06 11:45:30
149
+ # Environment: production
150
+ export ANTHROPIC_BASE_URL="https://api.anthropic.com"
151
+ export ANTHROPIC_AUTH_TOKEN="your-api-key"
152
+ # End CCM Environment Variables
153
+ ```
154
+
155
+ ## Build Process
156
+
157
+ 1. TypeScript compilation targets ES2020 with CommonJS modules
158
+ 2. Output goes to `dist/` directory with source maps
159
+ 3. CLI entry point is `dist/cli.js` with proper shebang
160
+ 4. Supports both development (`tsx`) and production (`node`) execution
161
+
162
+ ## Code Organization
163
+
164
+ ### CLI Structure (`src/cli.ts`)
165
+ - **performUseEnvironment()**: Shared function for consistent use behavior across commands
166
+ - **Command definitions**: Using Commander.js with proper option handling
167
+ - **Interactive prompts**: Inquirer.js integration for user input
168
+ - **Error handling**: Consistent error reporting and process exit codes
169
+
170
+ ### Shell Manager (`src/shell/ShellManager.ts`)
171
+ - **.ccmanrc management**: Independent file creation and updates
172
+ - **Shell reference management**: Minimal invasive approach
173
+ - **Auto-source capability**: Subprocess execution with error handling
174
+ - **Multi-shell support**: bash, zsh, fish detection and handling
175
+
176
+ ### Environment Manager (`src/config/EnvironmentManager.ts`)
177
+ - **High-level operations**: Add, remove, update, switch environments
178
+ - **Shell integration coordination**: Works with ShellManager for safe updates
179
+ - **Validation**: URL validation, environment name checking
180
+ - **Statistics**: Usage tracking and reporting
181
+
182
+ ## Recent Major Changes
183
+
184
+ 1. **Shell Architecture Redesign**: From direct modification to .ccmanrc + reference approach
185
+ 2. **Environment Variable Renaming**: Updated to ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN
186
+ 3. **Interactive Source Control**: Added user choice for manual vs automatic sourcing
187
+ 4. **Unified Use Logic**: Single function for consistent behavior across all use scenarios
188
+ 5. **Time Format Improvement**: Human-readable timestamps instead of ISO format
189
+ 6. **Enhanced config Command**: Complete menu-driven interface for all operations
190
+ 7. **Clear All Functionality**: Added clearAll command for complete CCM reset with confirmation
191
+
192
+ ## Testing Approach
193
+
194
+ - Manual testing of CLI interactions
195
+ - Verification of file system operations
196
+ - Shell integration testing across different shells
197
+ - Error condition handling validation
198
+ - User experience flow testing
199
+
200
+ ## Important Notes for Development
201
+
202
+ - **Always test shell integration**: Verify .ccmanrc creation and shell reference addition
203
+ - **Test interactive flows**: Ensure prompts work correctly in different scenarios
204
+ - **Validate file operations**: Check permissions and error handling
205
+ - **Cross-shell compatibility**: Test with bash, zsh, and fish when possible
206
+ - **User experience focus**: Prioritize clear messaging and helpful guidance
207
+
208
+ ## Future Enhancement Areas
209
+
210
+ - Configuration validation and migration
211
+ - Backup and restore functionality
212
+ - Environment templates or presets
213
+ - Integration with external credential stores
214
+ - Enhanced error reporting and diagnostics
215
+ - Network connectivity testing for environments