8000 GitHub - Songwo/AI-Term: 一个面向多 AI CLI 场景的配置管理工具 · GitHub
[go: up one dir, main page]

Skip to content
SongwoPublic

About

一个面向多 AI CLI 场景的配置管理工具

Topics

Resources

Stars

4 stars

Watchers

0 watching

Forks

Repository files navigation

AI-Nexus

一个面向多 AI CLI 场景的配置管理工具。

AI-Nexus 的目标是解决这几个实际问题:

  • 你需要在多个账号、多个服务、多个模型之间快速切换。
  • 你不希望把 API Key 长期写进系统环境变量。
  • 你希望把本地配置同步到不同 CLI(如 Codex、Claude、Gemini)对应的官方配置文件。
  • 你希望有清晰、可审计、可复制的命令行工作流。

为什么用 AI-Nexus

  • 统一管理:一个入口管理 Claude / OpenAI / DeepSeek / Gemini / 自定义服务。
  • 安全存储:API Key 使用 Fernet 加密后保存到本地配置文件。
  • 运行隔离:ai-nexus run 仅对当前子进程注入环境变量,不污染全局环境。
  • 模板同步:可同步到 .env、config.toml、settings.json、auth.json 等目标文件。
  • 交互友好:内置交互式流程,适合日常快速切换。

目录


安装

环境要求

  • Python 3.9 - 3.12(推荐 3.12)
  • Windows / Linux / macOS

Windows

# 标准安装(推荐)
install.bat

# 兼容性/简化安装
install-simple.bat

# 修复特定依赖问题(可选)
fix-pydantic.bat

Linux / macOS

chmod +x install.sh
./install.sh

手动安装

pip install -r requirements.txt
pip install -e .

安装完成后,可直接运行:

ai-nexus --help

5 分钟快速上手

1) 创建配置

ai-nexus add

按提示输入:

  • 配置名称(支持空格)
  • 服务类型(claude / openai / deepseek / gemini / custom)
  • API Key
  • API Base URL
  • 模型(可选)
  • 额外环境变量(可选)

2) 查看配置

ai-nexus list

3) 用该配置启动命令

ai-nexus run "my-profile" "your-cli-command"

例如:

ai-nexus run "GGBoom-Codex API" "codex"

4) 一键启动流程(推荐)

ai-nexus start

start 会引导你:

  • 选择已有配置 / 编辑配置 / 新建配置 / 删除配置
  • 选择是否同步模板
  • 进行连通性检测
  • 最终启动目标命令

核心概念

1) Profile(配置)

Profile 是 AI-Nexus 的基础单元,包含:

  • name:配置名
  • service:服务类型
  • api_key:密钥(加密保存)
  • api_base:接口地址
  • model:默认模型
  • env_vars:额外环境变量
  • cli_params:按模板保存的扩展参数

2) Template(模板)

Template 决定“如何把 Profile 同步到目标 CLI 的文件结构”。

内置模板包括:

  • codex-official(mode=codex)
  • claude-env(mode=env)
  • gemini-env(mode=env)

你也可以通过 template-add 自定义模板。

3) 同步模式

  • codex:写入 config.toml,可选写入 auth.json
  • env:写入 .env,对 Claude 还会同步 settings.json
  • json:写入 JSON 配置文件

配置文件与数据位置

AI-Nexus 自身配置目录:

  • ~/.ai-nexus/config.json:加密后的 Profile 数据
  • ~/.ai-nexus/history.log:运行历史
  • ~/.ai-nexus/.key:加密密钥
  • ~/.ai-nexus/templates.json:用户模板与内置模板状态

常见目标文件(由模板决定):

  • Codex:~/.codex/config.toml、~/.codex/auth.json
  • Claude:~/.claude/.env、~/.claude/settings.json
  • Gemini:~/.gemini/.env

命令总览

ai-nexus add
ai-nexus list
ai-nexus show <name>
ai-nexus edit <name>
ai-nexus delete [name]
ai-nexus clone <source> <target>
ai-nexus rename <old_name> <new_name>

ai-nexus run <profile> "<command>"
ai-nexus select
ai-nexus export <profile>
ai-nexus shell-init

ai-nexus test [profile]
ai-nexus history [--limit N]
ai-nexus info

ai-nexus template-list [--cli <cli>]
ai-nexus template-add
ai-nexus template-edit <name>
ai-nexus template-delete <name>
ai-nexus template-restore <name>

ai-nexus sync [--profile <name>] [--template <name>] [--write-auth-key]
ai-nexus start [--profile <name>] [--cmd <command>
8000
;] [--template <name>] [--write-auth-key]

ai-nexus codex-config-overwrite [--yes]
ai-nexus codex-auth-set [--value <key>] [--yes] [--clear]

命令速查表

类别 命令 用途
配置管理 add / list / show / edit / delete 新增、查看、编辑、删除配置
配置复用 clone / rename 复制或重命名配置
执行与注入 run / select / export / shell-init 使用配置运行命令、导出环境变量、生成 shell 初始化
连通性与审计 test / history / info 可用性检测、历史记录、系统信息
模板管理 template-list / template-add / template-edit / template-delete / template-restore 管理模板体系
模板同步 sync / start 同步模板并启动目标 CLI
Codex 专用 codex-config-overwrite / codex-auth-set 覆盖 config.toml、管理 auth.json

命令详解

配置管理

ai-nexus add

新增一个 Profile(交互式)。

ai-nexus list

列出所有配置,可选择是否进行连通性检测。

ai-nexus show <name>

查看指定配置详情。

ai-nexus edit <name>

编辑已有配置。

ai-nexus delete [name]

删除配置,支持两种方式:

  • 指定名称:ai-nexus delete "GGBoom-Codex API"
  • 不带参数:交互式选择删除项(推荐)

ai-nexus clone <source> <target>

克隆一份配置用于分环境管理。

ai-nexus rename <old_name> <new_name>

重命名配置。


运行与集成

ai-nexus run <profile> "<command>"

用指定配置运行命令,并将环境变量仅注入到该子进程。

示例:

ai-nexus run "Claude-FreeDuck专用" "claude"
ai-nexus run "GGBoom-Codex API" "codex"

ai-nexus select

先交互选配置,再输入命令执行。

ai-nexus export <profile>

导出环境变量(便于 shell 集成脚本使用)。

ai-nexus shell-init

生成 shell 初始化脚本片段。


检测与审计

ai-nexus test [profile]

  • 不带参数:测试全部配置
  • 带参数:测试指定配置

ai-nexus history [--limit N]

查看执行历史,默认 20 条。

ai-nexus info

查看平台、配置文件状态、统计信息。


模板管理

ai-nexus template-list [--cli <cli>]

查看模板列表(内置 + 用户模板)。

ai-nexus template-add

新增用户模板(交互式)。

ai-nexus template-edit <name>

编辑模板。编辑内置模板时会生成同名用户模板覆盖。

ai-nexus template-delete <name>

删除模板:

  • 用户模板:直接删除
  • 内置模板:标记为禁用

ai-nexus template-restore <name>

恢复被禁用的内置模板。


同步与启动

ai-nexus sync

将 Profile 同步到目标模板文件,支持:

  • 交互选择 profile/template
  • 运行模板参数采集
  • 可选写入官方 auth 文件(针对支持的模板)

示例:

ai-nexus sync --profile "GGBoom-Codex API" --template codex-official --write-auth-key

ai-nexus start

统一入口(推荐日常使用):

  • 选择启动方式:直接启动 / 编辑后启动 / 新建后启动 / 删除配置
  • 可选模板同步
  • 可选连通性检测
  • 启动最终命令

示例:

ai-nexus start
ai-nexus start --profile "Claude-FreeDuck专用" --cmd "claude"

Codex 专用命令

ai-nexus codex-config-overwrite [--yes]

粘贴 TOML 并直接覆盖 ~/.codex/config.toml。

ai-nexus codex-auth-set [--value <key>] [--yes] [--clear]

管理 ~/.codex/auth.json(仅保留 OPENAI_API_KEY 字段):

  • 设置/覆盖 Key
  • 检测到已有配置时可交互选择覆盖/删除/取消
  • --clear 仅删除已有 auth 文件

实战教程

场景 1:Claude 接入 + 自定义模型字段

目标:把配置同时写入 ~/.claude/.env 和 ~/.claude/settings.json,并管理扩展模型字段。

步骤:

  1. 创建配置
ai-nexus add
  1. 同步到 Claude 模板
ai-nexus sync --profile "Claude-FreeDuck专用" --template claude-env
  1. 在参数交互中可配置:
  • ANTHROPIC_DEFAULT_OPUS_MODEL
  • ANTHROPIC_DEFAULT_SONNET_MODEL
  • ANTHROPIC_DEFAULT_HAIKU_MODEL
  • CLAUDE_CODE_SUBAGENT_MODEL
  • settings.json 顶层 model(haiku/sonnet/opus)
  1. Claude 模型快捷预设

在 claude-env 参数流程中内置“快捷预设”:

  • 用当前主模型填充全部扩展模型
  • 输入统一模型并填充
  • 一键清空扩展模型字段
  • 同时设置顶层 model

说明:ANTHROPIC_AUTH_TOKEN 会强制与 ANTHROPIC_API_KEY 保持一致。


场景 2:Codex 官方配置同步

目标:同步 config.toml,并安全写入 auth.json。

步骤:

  1. 同步模板
ai-nexus sync --profile "GGBoom-Codex API" --template codex-official --write-auth-key
  1. 当检测到已有 auth.json 时,会先检查登录状态,再让你选择:
  • 退出并覆盖
  • 仅删除旧配置
  • 取消
  1. 最终 auth.json 仅保留:
{
  "OPENAI_API_KEY": "..."
}

场景 3:一台机器管理多账号

你可以维护多套配置:

  • Claude-FreeDuck专用
  • GGBoom-Codex API
  • work-openai
  • personal-openai

并在不同命令中切换:

ai-nexus run "work-openai" "python script.py"
ai-nexus run "personal-openai" "python script.py"

场景 4:项目级隔离

在不同项目目录使用不同 Profile:

cd project-a
ai-nexus run "GGBoom-Codex API" "codex"

cd ../project-b
ai-nexus run "Claude-FreeDuck专用" "claude"

常见问题

1) 删除带空格名称失败怎么办

直接使用交互删除:

ai-nexus delete

或者加引号:

ai-nexus delete "GGBoom-Codex API"

2) 为什么同步后只看到 .env

请确认使用的是 claude-env 模板。当前实现会为 Claude 同步 .env + settings.json。

3) 如何清空 Codex 旧认证

ai-nexus codex-auth-set --clear

4) 如何查看当前系统状态

ai-nexus info

安全建议

  • 优先使用 ai-nexus run,避免长期导出全局环境变量。
  • 定期轮换 API Key,旧 Key 可通过编辑配置更新。
  • 不要把真实密钥提交到 Git 仓库。
  • 对生产环境配置使用独立 Profile,避免误用测试配置。

许可证

MIT

About

一个面向多 AI CLI 场景的配置管理工具

Topics

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0