feat(cli): V1.22.0-alpha tagent config CLI — 多模型 onboarding Step 2#81
Merged
Conversation
新增 `tagent config` 子命令, 解锁 LLM provider 一键切换. README 命令名同步. ## 变更 ### 1. runtime/cli/config.py (新, 4 子命令) | 命令 | 行为 | |---|---| | `tagent config list` | 列内置 6 厂商 (路径 A) + 5 兼容样例 (路径 B) | | `tagent config show` | 显当前 .env (TAGENT_LLM_* + 厂商 key 全脱敏 4+4) | | `tagent config use <name>` | 路径 A: 写 TAGENT_LLM_PROVIDER + 厂商 key 占位 | | `tagent config use-compat --base --key --model` | 路径 B: OpenAI 兼容兜底通道 | helper: - `_find_env_file()` — 当前 CWD/.env - `_parse_env(p)` — 保留注释/引号 - `_write_env(p, env)` — 写前必备份 .env.bak - `_mask(s)` — key 脱敏 4 头 4 尾 ### 2. runtime/cli/main.py (+2 行) ```python from runtime.cli.config import config_app app.add_typer(config_app, name="config") ``` ### 3. runtime/tests/test_cli_config.py (新, 15 case) - helper 单元: _mask 短/长 / _parse_env 注释/缺失 / _write_env 备份策略 / _find_env_file - CLI 集成 (CliRunner + tmp_path + monkeypatch.chdir): - list 含 6 内置 + 兼容样例 + cookbook link - show 脱敏 / 缺文件 hint - use 写 provider + 占位 + 清 B 路径残值 - use 未知 provider exit 2 - use ollama 显本地启动提示 - use-compat 写 3 env + key 脱敏不泄 ### 4. README.md + README.zh-CN.md (#69 5 Key #3) `tagent model` → `tagent config use <name>` + `tagent config use-compat` (原 `tagent model` 仅 README 提及, 从未实装. 此 PR 让 README 与 CLI 对齐.) ## 测试 - [x] pytest runtime/tests/test_cli_config.py: 15/15 PASSED (0.21s) - [x] pytest runtime/tests/ 全 regression: 83 passed, 2 skipped (0 fail) - [x] ruff check runtime/cli/config.py runtime/tests/test_cli_config.py: clean - [x] `tagent --help` / `tagent config --help` 实测显 4 子命令 - [ ] CI 13 必修绿
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
摘要
新增
tagent config子命令组, 解锁 LLM provider 一键切换. 实装 V1.21 后多 provider 通道的 onboarding 路径, README 命令名同步.Step 2 收尾 (多模型 onboarding 3 步: Step 3 通用 env 通道 PR #79 ✅ · Step 1 README 卖点 PR #80 ✅ · Step 2 config CLI 本 PR).
变更
1.
runtime/cli/config.py新 (193 行)4 子命令:
tagent config listtagent config showtagent config use <name>tagent config use-compat --base --key --modelhelper (4):
_find_env_file()— 当前 CWD/.env_parse_env(p)— 保留注释 / 引号 strip / 缺失返 {}_write_env(p, env)— 写前必备份 .env.bak (覆盖)_mask(s)— key 脱敏 4 头 4 尾provider 模型名严格对齐
runtime/router/llm_client.py:PROVIDER_MODEL_MAP(claude / openai / gemini / qwen / deepseek / ollama).2.
runtime/cli/main.py(+2 行)(main.py 9 个 pre-existing ruff issue 不在本 PR scope.)
3.
runtime/tests/test_cli_config.py新 (149 行 / 15 case)helper 单元 7:
_mask短返***/ 长返 4+4_parse_env注释 / 引号 strip / 缺失返 {}_write_env备份策略 (已存生 .bak / fresh 不生)_find_env_fileCWDCLI 集成 8 (CliRunner + tmp_path + monkeypatch.chdir):
list含 6 内置 + 兼容样例 + cookbook linkshow脱敏 / 缺文件 hintuse写 provider + 占位 + 清 B 路径残值use未知 provider exit 2use ollama显本地启动提示use-compat写 3 env + key 不泄4. README.md + README.zh-CN.md (#69 5 Key #3)
tagent model→tagent config use <name>+tagent config use-compat(原
tagent model仅 README 提及, 从未实装. 此 PR 让 README 与 CLI 对齐, 不再说不实之话.)测试
pytest runtime/tests/test_cli_config.py -v: 15/15 PASSED (0.21s)pytest runtime/tests/全 regression: 83 passed, 2 skipped (0 fail)ruff check runtime/cli/config.py runtime/tests/test_cli_config.py: cleantagent --help实测显config子组tagent config --help实测显 4 子命令关联
tagent config use claude直接生 .env后续 (followup, 不在 scope)
tagent config unset子命令清 LLM 段tagent config use之后自动跑tagent doctor --llm-smoke验路由