feat(config): add active profile selection

- persist the active profile in config.json
- resolve config with --config > active_config > default
- add config list and config use commands
- make auth and config writes target the selected profile
- reset activation to default when deleting the active profile
- update config UI with profile activation controls
- keep token refresh and pipeline execution profile-aware
- add loader, UI, auth, and CLI interaction coverage
This commit is contained in:
若麒
2026-07-16 11:05:59 +08:00
parent 75a45e1a2a
commit de9f1a3889
26 changed files with 825 additions and 102 deletions
+1 -1
View File
@@ -37,7 +37,7 @@ defineCommand({ auth }) → runtime/authStage → ctx.client → command.run(ctx
- `bl auth login --console` 只更新 `access_token` 以及回调携带的 console 作用域字段
- `bl auth login --open-api ...` 只更新 `access_key_id` / `access_key_secret`
- `bl auth logout --console` 只清 `access_token`
- `bl auth logout --open-api` 只清 `access_key_id` / `access_key_secret`
- `bl auth logout --open-api` 只清 `access_key_id` / `access_key_secret` / `security_token`
- `bl auth logout` 清 `api_key` + `access_token` + `access_key_*`
解析分工:
+69
View File
@@ -0,0 +1,69 @@
# Config Profile 与激活状态变更清单
适用于新增 Profile 预设、修改命名 Profile 选择规则、调整 `active_config`,或新增/修改 `bl config list/use/show/ui` 等 Profile 管理能力。
## 1. 保持存储边界
- Profile 业务字段继续由 `ConfigFile` / `CONFIG_FILE_KEYS` 管理。
- `active_config` 是 `config.json` 顶层元数据,不得进入命名 Profile block,也不得被 `config set` 当作普通字段写入。
- 识别命名 Profile 时必须排除业务字段和顶层元数据。
- 旧配置缺少 `active_config` 时继续等价于激活 `default`。
## 2. 保持选择语义
```text
显式 --config <name> > active_config > default
```
- 解析阶段用局部变量保留“是否显式传入 `--config`”的信息;完成 Config 选择后不进入 `Settings`。
- `--config default` 必须显式选择顶层配置并绕过命名激活项。
- `--config` 和 `auth login --config ...` 不得隐式修改持久化激活状态。
- 激活状态只选择配置 block,不改变字段优先级;字段仍为 flag > env > selected config > 默认值。
- Pipeline 等进程内调用链也要复用统一的 `buildSources()`,避免绕过激活状态。
- Console access token 自动刷新等后台读写必须携带 `settings.configName`,不得直接读写顶层 default。
## 3. 保持读写命令交互一致
- `auth login`、`config set` 等写命令未传 `--config` 时修改当前激活项。
- 写命令显式指定不存在的 `--config <name>` 时,仅在业务操作成功并实际落盘时创建 Profile。
- `config show`、`auth status` 和业务消费等读命令不得因为显式指定不存在的名称而创建 Profile。
- `auth logout` 默认只清理当前激活项;显式 `--config` 只清理指定项。
- 按凭证域退出时必须清理该域的完整字段集合,例如 OpenAPI 同时清理 AK、SK 和 STS `security_token`。
- 所有生产代码读取“当前配置”时优先经过 `buildSources()` 或携带解析后的 `configName`;直接调用无名称的 `readConfigFile()` / `writeConfigFile()` 只适用于明确操作顶层 default 的底层能力。
## 4. 保持状态一致性
- `config use` 只能激活已经存在的命名 Profile;`default` 始终有效。
- 配置文件中的 `active_config` 指向不存在的 Profile 时返回 usage error,不静默回退。
- 删除当前激活的命名 Profile 时,同一次落盘切回 `default`,不得留下悬空引用。
- 配置写入继续使用临时文件 + rename,避免中断后留下半写文件。
## 5. 命令与展示联动
- 新增/重命名命令时同步 `packages/commands/src/index.ts` 和产品入口 `packages/cli/src/commands.ts`。
- `config list` 标识所有 Profile 与当前激活项。
- `config show`、`auth status` 只输出本次最终选择的 `config` 和 `config_file`,不重复携带激活状态。
- `config ui` 从持久化元数据读取激活项,提供显式激活操作,并在删除激活项后刷新为 `default`。
- 同步 E2E topic routes、Skill setup 和自动生成 reference。
## 6. 最小测试矩阵
- 旧配置无 `active_config` -> `default`。
- 激活命名 Profile 后,无 `--config` 的命令选择该 Profile。
- 显式命名 `--config` 和 `--config default` 均覆盖激活项且不修改磁盘状态。
- 激活不存在的 Profile 失败且不写盘。
- 悬空 `active_config` 明确失败。
- 删除激活 Profile 后切回 `default`。
- 登录、退出、`config set` 分别覆盖“当前激活项”和“显式不存在名称成功后创建”。
- Console token 自动刷新不从其他 Profile 借用 AK/SK,也不把新 token 写入其他 Profile。
- `config list/show/use/ui`、`auth status` 和依赖默认模型的消费命令覆盖对应 E2E。
## 7. 完成检查
```sh
pnpm run sync:skill-assets
vp check
vp test
```
命令 E2E 会启动本地子进程,Config UI 测试还会监听 `127.0.0.1` 临时端口;受限沙箱内出现 `EPERM` 时,需要在允许本地进程和端口的环境中复跑。
+11 -5
View File
@@ -1,6 +1,6 @@
# Token Plan Profile 与激活配置接入方案
> 状态:Token Plan 模型消费 MVP 已实现;Config 激活状态和通用 Base URL 归一化待实现。
> 状态:Token Plan 模型消费 MVP 与 Config 激活状态已实现;通用 Base URL 归一化待实现。
>
> 目标分支:`feat/cli-access-token`。
@@ -163,7 +163,7 @@ token-plan *
- 未传 `--config`:展示当前激活的 Config。
- 传 `--config <name>`:展示指定 Config,不改变激活状态。
- 输出中包含 `config`、`active` 和 `config_file`。
- 输出中包含最终选择的 `config` 和 `config_file`;激活状态统一由 `config list` / `config ui` 展示。
`config ui` 应展示当前激活项,并提供激活操作。
@@ -453,7 +453,7 @@ feat(cli): enable token-plan text and image consumption
- [ ] 增加 `auth login --config token-plan --api-key ...`、文本消费和图片消费示例。
- [ ] 与届时实际上线范围核对模型名称、服务地域、限制条件和用户措辞。
### Commit 4:Config 激活状态与切换命令(待实现)
### Commit 4:Config 激活状态与切换命令(已实现)
建议提交信息:
@@ -468,12 +468,18 @@ feat(config): add active profile selection
- 保证 `--config default` 能显式覆盖激活项。
- 新增 `bl config list`。
- 新增 `bl config use --name <name>`。
- `config show`、`auth status` 和 `config ui` 展示激活状态。
- `config show`、`auth status` 展示最终选择项,`config list` 和 `config ui` 展示激活状态。
- 删除激活 Profile 时处理状态一致性。
- 验证激活 `token-plan` 后不传 `--config` 的文本和图片请求。
- 验证临时 `--config default` 不改变激活状态。
- 更新命令导出、`packages/cli/src/commands.ts`、E2E 和生成 reference。
实现选择:删除当前激活的命名 Profile 时,在同一次配置文件写入中将 `active_config` 重置为 `default`。`auth login --config <name>` 和所有显式 `--config` 仍只作用于本次命令,不修改激活状态。
相关写入交互统一为:`auth login`、`auth logout` 和 `config set` 未传 `--config` 时作用于当前激活项;显式指定名称时作用于该名称。写命令可在成功落盘时创建不存在的 Profile,读命令不创建。Console access token 自动刷新同样限定在当前选中的 Profile,不得回退读写顶层 default。
激活项选择的是完整 Config,而不是只选择模型消费凭证。激活 `token-plan` 后,Token Plan 管控命令也会从该 Profile 解析 OpenAPI AK/SK,Console 命令也会从该 Profile 解析 Console 凭证。如果相应凭证仍保存在顶层 `default`,用户需要为单次命令显式传入 `--config default`,或将对应凭证域登录到 `token-plan`;CLI 不为不同鉴权域做隐式跨 Profile 回退。
### Commit 5:通用模型 Base URL 归一化(待实现)
建议提交信息:
@@ -532,7 +538,7 @@ vp check
vp test
```
完成改动后,应评估“Profile 预设与激活状态”是否需要沉淀为新的 `docs/agents/config-profile-change.md` 场景清单。
“Profile 预设与激活状态”的维护要求已沉淀到 `docs/agents/config-profile-change.md`。
## 最终结论