Skip to content
This repository was archived by the owner on Nov 14, 2026. It is now read-only.
GuccbaiPublic archive

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

WeCode Setup

一键配置 WeCode Codex CLI 环境的自动化工具。

✨ 功能特性

  • 🚀 自动安装依赖: 自动检测并安装 Node.js、npm(如需要)
  • 📦 CLI 自动安装: 自动安装 OpenAI Codex CLI
  • 🔧 智能配置: 自动配置 Codex CLI 连接到 WeCode API
  • 🌍 环境变量管理: 自动配置环境变量到系统(支持 bash/zsh/fish/Windows)
  • ⚡ 立即生效: 配置完成后当前终端窗口立即可用,无需重启
  • 🖥️ 跨平台支持: 支持 macOS、Linux、WSL、Windows

📥 下载安装

方式一:直接下载预编译二进制文件

从 Releases 页面下载对应平台的可执行文件:

  • macOS: wecode_setup_macos_universal(通用二进制,支持 Intel 和 Apple Silicon)
  • Linux ARM64: wecode_setup_linux_arm64
  • Linux AMD64: wecode_setup_linux_amd64
  • Windows AMD64: wecode_setup_windows_amd64.exe

方式二:从源码编译

# 克隆仓库
git clone https://github.com/Guccbai/wecode_setup.git
cd wecode_setup

# 编译
go build -o wecode_setup

# 运行
./wecode_setup

🚀 快速开始

1. 运行工具

# macOS/Linux
chmod +x wecode_setup_*
./wecode_setup_macos_universal

# Windows
wecode_setup_windows_amd64.exe

2. 输入 API Key

工具启动后,按提示输入您的 WeCode API Key(以 cr_ 开头,共 67 个字符):

======================================================================
WeCode Codex CLI 配置工具
======================================================================

📝 请输入 WeCode API Key(以 cr_ 开头),或输入 'clear' 清除配置

> cr_your_api_key_here...

3. 完成配置

工具会自动完成以下操作:

  1. ✅ 检测并安装 Node.js/npm(如需要)
  2. ✅ 配置 npm 国内镜像源(提升下载速度)
  3. ✅ 安装 OpenAI Codex CLI
  4. ✅ 配置 Codex CLI 连接到 WeCode API
  5. ✅ 配置环境变量 CRS_OAI_KEY(当前终端立即生效 + 持久化)

4. 验证安装

配置完成后,在当前终端即可使用:

# 验证 Codex CLI 安装
codex --version

# 验证环境变量
echo $CRS_OAI_KEY  # macOS/Linux
echo %CRS_OAI_KEY%  # Windows

🔧 使用说明

配置 Codex CLI

./wecode_setup

# 输入 API Key 并回车
> cr_your_api_key_here...

配置文件位置:

  • ~/.codex/config.toml: Codex CLI 配置文件
  • ~/.codex/auth.json: 认证配置文件
  • 环境变量自动写入:
    • macOS/Linux: ~/.zshrc 或 ~/.bashrc 或 ~/.profile
    • Windows: 用户级系统环境变量

清除配置

./wecode_setup

# 输入 clear 并回车
> clear

这将删除 ~/.codex/ 目录下的所有配置文件。

环境变量立即生效机制

工具采用双重保障策略:

  1. 当前进程立即生效: 使用 os.Setenv() 直接设置当前终端环境变量
  2. 持久化配置: 写入 shell 配置文件,确保新终端自动加载

优势:

  • ✅ 配置完成后当前终端立即可用,无需重启或 source
  • ✅ 新打开的终端窗口自动加载环境变量
  • ✅ 其他已打开的终端可通过 source ~/.zshrc 手动加载

📋 系统要求

自动安装模式

工具会自动检测并安装依赖,支持以下包管理器:

  • macOS: Homebrew (brew)
  • Linux: apt/apt-get、dnf、yum、pacman
  • Windows: winget 或 Chocolatey (choco)
  • WSL: 与 Linux 相同

手动安装模式

如果工具无法自动安装依赖,请手动安装以下软件:

  • Node.js: >= 14.x(推荐 LTS 版本)
  • npm: >= 6.x(通常随 Node.js 安装)

手动安装后重新运行 wecode_setup 即可。

🌐 支持的 Shell

工具自动检测并配置以下 Shell 环境:

Shell 配置文件 检测方式
zsh ~/.zshrc, ~/.zprofile $SHELL 环境变量
bash ~/.bashrc, ~/.bash_profile, ~/.profile $SHELL 环境变量
fish ~/.config/fish/config.fish $SHELL 环境变量
其他 ~/.profile 默认回退

🔑 API Key 说明

格式要求

  • 前缀: 必须以 cr_ 开头
  • 长度: 正好 67 个字符
  • 示例: cr_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

获取 API Key

请访问 WeCode 平台 获取您的 API Key。

安全建议

  • ⚠️ 不要将 API Key 提交到版本控制系统
  • ⚠️ 不要在公共场合分享您的 API Key
  • ⚠️ 定期轮换 API Key 以提升安全性

📁 项目结构

wecode_setup/
├── main.go                    # 程序入口
├── internal/
│   └── setup/
│       └── setup.go           # 核心逻辑(672 行)
├── go.mod                     # Go 模块定义
├── README.md                  # 本文档
└── CLAUDE.md                  # 项目开发指南

🛠️ 开发指南

构建项目

# 当前平台
go build -o wecode_setup

# 跨平台编译
# macOS Universal
GOOS=darwin go build -o wecode_setup_macos_universal

# Linux ARM64
GOOS=linux GOARCH=arm64 go build -o wecode_setup_linux_arm64

# Linux AMD64
GOOS=linux GOARCH=amd64 go build -o wecode_setup_linux_amd64

# Windows AMD64
GOOS=windows GOARCH=amd64 go build -o wecode_setup_windows_amd64.exe

运行测试

# 运行所有测试
go test ./...

# 详细输出
go test -v ./...

# 特定包
go test ./internal/setup

代码风格

项目遵循 Go 标准代码风格:

# 格式化代码
go fmt ./...

# 静态检查
go vet ./...

🔍 常见问题

Q: 提示 "Codex CLI 仍未检测到"

A: 可能是 npm 全局安装路径不在 $PATH 中。解决方案:

# macOS/Linux: 添加 npm 全局路径到 PATH
export PATH="$PATH:$(npm config get prefix)/bin"

# 或手动安装 Codex CLI
npm install -g @OpenAI/codex --registry https://registry.npmmirror.com/

Q: Windows 环境变量不生效

A: Windows 使用 setx 设置的环境变量需要重新打开终端窗口才能生效(新终端会话)。当前终端通过 os.Setenv() 已设置,可立即使用。

Q: 如何更换 API Key

A: 直接重新运行工具并输入新的 API Key 即可,会自动覆盖旧配置。

Q: 如何手动配置环境变量

A: 如果自动配置失败,可手动添加:

# macOS/Linux (bash)
echo 'export CRS_OAI_KEY=your_api_key' >> ~/.bash_profile
source ~/.bash_profile

# macOS/Linux (zsh)
echo 'export CRS_OAI_KEY=your_api_key' >> ~/.zshrc
source ~/.zshrc

# Windows (PowerShell 管理员模式)
[Environment]::SetEnvironmentVariable("CRS_OAI_KEY", "your_api_key", "User")

Q: 支持代理环境吗?

A: 支持。npm 会自动读取系统代理设置。如需手动配置:

# 设置 npm 代理
npm config set proxy http://proxy.example.com:8080
npm config set https-proxy http://proxy.example.com:8080

# 或使用环境变量
export HTTP_PROXY=http://proxy.example.com:8080
export HTTPS_PROXY=http://proxy.example.com:8080

🤝 贡献指南

欢迎提交 Issue 和 Pull Request!

提交 Issue

  • 🐛 Bug 报告:请包含操作系统、Go 版本、错误日志
  • 💡 功能建议:请描述使用场景和预期行为

提交 PR

  1. Fork 本仓库
  2. 创建特性分支 (git checkout -b feature/AmazingFeature)
  3. 提交更改 (git commit -m 'Add some AmazingFeature')
  4. 推送到分支 (git push origin feature/AmazingFeature)
  5. 开启 Pull Request

📄 许可证

本项目采用 MIT 许可证 - 详见 LICENSE 文件。

🙏 致谢

📞 联系方式


享受便捷的 WeCode Codex CLI 配置体验! 🚀

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages