Compare commits
1 Commits
@@ -47,6 +47,7 @@ Codex home 的解析顺序:
|
||||
- `cdxs alias remove <别名或账号>`:删除指定账号的别名。
|
||||
- `cdxs switch`:不带参数时自动选择可用配额最优的账号。
|
||||
- `cdxs switch <账号或别名>`:切换到指定账号,OAuth 和 API Key 账号都可通过 alias 切换。
|
||||
- `cdxs switch -f <账号或别名>`:切换账号并同步 Codex resume 会话的 provider 状态;普通 `switch` 不修改会话数据库。
|
||||
- `cdxs switch A --model <model> --effort <effort> --name OpenAI`:切换时更新该账号默认模型、思考程度;`--name` 仅用于 API 模式的 provider name。
|
||||
- `cdxs exec <账号> -- --model gpt-5 "hello"`:用指定账号运行 `codex exec`。
|
||||
- `cdxs exec <home> --home --temp -- --model gpt-5 "hello"`:基于指定受管 home 建立一次性临时 `CODEX_HOME` 后运行 `codex exec`。
|
||||
|
||||
@@ -15,6 +15,7 @@ pub async fn switch_account(
|
||||
codex_home: Option<PathBuf>,
|
||||
apply_fingerprint: bool,
|
||||
options: SwitchOptions,
|
||||
force: bool,
|
||||
) -> Result<()> {
|
||||
if apply_fingerprint {
|
||||
eprintln!("提示: M1 尚未实现设备指纹应用,已忽略 --apply-fingerprint。");
|
||||
@@ -26,13 +27,14 @@ pub async fn switch_account(
|
||||
let mut store = Store::load(&config_home)?;
|
||||
let account_id = find_unique_account_id(&store, query)?;
|
||||
update_account_switch_options(&mut store, &account_id, &options)?;
|
||||
switch_account_id(&mut store, &config_home, &target_home, &account_id).await
|
||||
switch_account_id(&mut store, &config_home, &target_home, &account_id, force).await
|
||||
}
|
||||
|
||||
pub async fn switch_auto(
|
||||
codex_home: Option<PathBuf>,
|
||||
apply_fingerprint: bool,
|
||||
options: SwitchOptions,
|
||||
force: bool,
|
||||
) -> Result<()> {
|
||||
if apply_fingerprint {
|
||||
eprintln!("提示: M1 尚未实现设备指纹应用,已忽略 --apply-fingerprint。");
|
||||
@@ -56,7 +58,7 @@ pub async fn switch_auto(
|
||||
}
|
||||
let account_id = best_auto_switch_account(&store)?;
|
||||
update_account_switch_options(&mut store, &account_id, &options)?;
|
||||
switch_account_id(&mut store, &config_home, &target_home, &account_id).await?;
|
||||
switch_account_id(&mut store, &config_home, &target_home, &account_id, force).await?;
|
||||
if let Some(account) = store.find_account(&account_id) {
|
||||
println!(
|
||||
"自动选择账号: {} <{}> plan={} quota={}",
|
||||
@@ -88,7 +90,6 @@ pub async fn prepare_account_in_home(query: &str, codex_home: PathBuf) -> Result
|
||||
codex_config::apply_account_provider(&codex_home, account)?;
|
||||
(account.id.clone(), account.email.clone())
|
||||
};
|
||||
session::align_provider_buckets(&codex_home)?;
|
||||
if let Some(account) = store.find_account_mut(&account_id) {
|
||||
account.last_used_at = Utc::now().timestamp();
|
||||
}
|
||||
@@ -113,6 +114,7 @@ async fn switch_account_id(
|
||||
config_home: &Path,
|
||||
target_home: &Path,
|
||||
account_id: &str,
|
||||
force: bool,
|
||||
) -> Result<()> {
|
||||
token::refresh_account_if_needed(store, account_id).await?;
|
||||
let account = store
|
||||
@@ -120,7 +122,16 @@ async fn switch_account_id(
|
||||
.ok_or_else(|| anyhow!("账号不存在: {account_id}"))?;
|
||||
auth_file::write_account_to_auth(&paths::auth_path(target_home), target_home, account)?;
|
||||
codex_config::apply_account_provider(target_home, account)?;
|
||||
session::align_provider_buckets(target_home)?;
|
||||
if force {
|
||||
let summary = session::align_provider_buckets(target_home)?;
|
||||
println!(
|
||||
"已同步 resume 会话 provider: provider={}, sqlite_threads={}, rollouts={}/{}",
|
||||
summary.provider,
|
||||
summary.updated_threads,
|
||||
summary.updated_rollouts,
|
||||
summary.checked_rollouts
|
||||
);
|
||||
}
|
||||
if let Some(account) = store.find_account_mut(account_id) {
|
||||
account.last_used_at = Utc::now().timestamp();
|
||||
}
|
||||
|
||||
@@ -57,6 +57,8 @@ pub enum Commands {
|
||||
account: Option<String>,
|
||||
#[arg(short, long, conflicts_with = "account")]
|
||||
auto: bool,
|
||||
#[arg(short, long, help = "Also rewrite Codex resume session provider state")]
|
||||
force: bool,
|
||||
#[arg(long)]
|
||||
codex_home: Option<PathBuf>,
|
||||
#[arg(long)]
|
||||
|
||||
+3
-1
@@ -99,6 +99,7 @@ async fn main() -> Result<()> {
|
||||
Commands::Switch {
|
||||
account,
|
||||
auto,
|
||||
force,
|
||||
codex_home,
|
||||
apply_fingerprint,
|
||||
model,
|
||||
@@ -111,7 +112,7 @@ async fn main() -> Result<()> {
|
||||
provider_name: name,
|
||||
};
|
||||
if auto || account.is_none() {
|
||||
account::switch_auto(codex_home, apply_fingerprint, options).await
|
||||
account::switch_auto(codex_home, apply_fingerprint, options, force).await
|
||||
} else {
|
||||
account::switch_account(
|
||||
account.as_deref().ok_or_else(|| {
|
||||
@@ -120,6 +121,7 @@ async fn main() -> Result<()> {
|
||||
codex_home,
|
||||
apply_fingerprint,
|
||||
options,
|
||||
force,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user