Make Codex and Claude Code subscriptions go further: a local model router that gives routine agent work to economical models and keeps your strongest model for the hard parts.
Rust ai-agentsai-gatewayclaude-codecodexcoding-agentcost-optimizationdeepseekllm-gatewayllm-routerlocal-firstmodel-routingrusttask-routingtauri
fix(qoder): report native login requirements in model checks (#111)
澄潭4e3987b118e0
diff --git a/apps/desktop/src/features/agents/AdditionalModelEditor.tsx b/apps/desktop/src/features/agents/AdditionalModelEditor.tsxindex bb78823f..03cd0971 100644--- a/apps/desktop/src/features/agents/AdditionalModelEditor.tsx+++ b/apps/desktop/src/features/agents/AdditionalModelEditor.tsx@@ -31,6 +31,7 @@ export function AdditionalModelEditor({ agent, values, plans, language, disabled</label>)}</fieldset><div className="additional-model-editor__help">+ {agent.agent_id === 'agent_qoder_default' && <p className="field-help" data-qoder-login-prerequisite>{text('使用这些路由前,请先在对应的 Qoder CLI 中通过 /login 登录。保存路由不会完成 Qoder 登录。', 'Before using these routes, sign in with /login in the corresponding Qoder CLI. Saving routes does not sign in to Qoder.')}</p>}<p className="field-help" data-agent-activation>{dsh ? text('保存后启动 dsh web,在模型选择器中选用 HiRoute 路由。此配置作用于标准 web profile;其他 profile 保留原有配置。', 'After saving, start dsh web and select a HiRoute route in the model picker. This configures the standard web profile; other profiles retain their configuration.') : text(`保存后重新启动 ${name},通过 /model 明确选用已添加的 HiRoute 路由。未选择时继续使用原来的模型。`, `Restart ${name} after saving, then explicitly select an added HiRoute route with /model. Otherwise it keeps using your previous model.`)}</p><p className="field-help">{text(`在 HiRoute 中调整或移除这些路由。如果已将某条路由设为 ${name} 默认模型,移除前请先在 ${name} 中切换到其他模型。`, `Adjust or remove these routes in HiRoute. If one is now your ${name} default, switch to another model in ${name} before removing it.`)}</p></div>diff --git a/apps/desktop/src/features/agents/README.md b/apps/desktop/src/features/agents/README.mdindex e57c6fc9..334dbb30 100644--- a/apps/desktop/src/features/agents/README.md+++ b/apps/desktop/src/features/agents/README.md@@ -25,6 +25,11 @@ to their production owners and executable contracts.Qoder, Pi and DSH share the additional-route editor and explicitly selected Plan IDsthrough `qoder_additional`, `pi_additional` and `dsh_additional`. It does notedit the native default or show native catalogs, fixed-source choices or import controls.+Qoder's editor explains that the selected Qoder CLI must complete its own `/login`+before using these routes. Saving configuration does not perform native sign-in or+make a model call. A valid native login rejection in the separate Qoder Live check+remains a failed surface result with `LIVE_NATIVE_LOGIN_REQUIRED`; other native+business errors use `LIVE_CLIENT_FAILED`, while malformed output remains distinct.Its model configuration uses the existing Preview, protected token and independentrestore flow. A model restore keeps the collaboration Skill; a collaboration restorekeeps the model routes. Token updates retain the saved ecosystem-specific selection.diff --git a/apps/desktop/tests/v3/browser/agent-trust-scenarios.mjs b/apps/desktop/tests/v3/browser/agent-trust-scenarios.mjsindex 0bae57ce..6a8cca96 100644--- a/apps/desktop/tests/v3/browser/agent-trust-scenarios.mjs+++ b/apps/desktop/tests/v3/browser/agent-trust-scenarios.mjs@@ -546,6 +546,7 @@ const scenarios = [const pick = () => [...dialog().querySelectorAll('[data-agent-plan-id] input')].slice(0, 2).forEach(input => input.click());pick(); await tick();assert(dialog().textContent.includes('当前默认模型保持不变') && dialog().textContent.includes('/model'), 'Additional routing does not explain native preservation and selection');+ assert(dialog().querySelector('[data-qoder-login-prerequisite]')?.textContent.includes('/login'), 'Qoder routing does not explain its native login prerequisite');assert(!dialog().querySelector('[data-agent-default], [data-client-model-id], [data-agent-fixed-models]'), 'Qoder borrowed native model, source or default controls');assert(dialog().querySelectorAll('[data-plan-protocol] select').length === 2, 'Each selected route needs its own protocol choice');[...dialog().querySelectorAll('button')].find(button => button.textContent === '取消').click(); await tick();diff --git a/crates/daemon/src/control/runtime/agent_live_check_qoder.rs b/crates/daemon/src/control/runtime/agent_live_check_qoder.rsindex ad4f7ab5..022545da 100644--- a/crates/daemon/src/control/runtime/agent_live_check_qoder.rs+++ b/crates/daemon/src/control/runtime/agent_live_check_qoder.rs@@ -1,6 +1,8 @@//! A real Qoder print call selects the persisted provider; no route or credential overlay.use super::*;+const NATIVE_LOGIN_REQUIRED: &str = "LIVE_NATIVE_LOGIN_REQUIRED";+impl LocalControlAdapter {#[cfg(unix)]pub(super) fn execute_qoder_live_attempt(@@ -113,9 +115,6 @@ impl LocalControlAdapter {thread::sleep(Duration::from_millis(20));};child.stop().map_err(|_| failure(CLIENT_FAILED))?;- if !success {- return Err(failure(CLIENT_FAILED));- }let mut bytes = zeroize::Zeroizing::new(Vec::new());std::fs::File::open(&output_path).map_err(|_| failure(CLIENT_OUTPUT_INVALID))?@@ -125,7 +124,7 @@ impl LocalControlAdapter {if bytes.len() > OUTPUT_LIMIT {return Err(failure(CLIENT_OUTPUT_INVALID));}- let identity = parse_qoder_output(&bytes).ok_or_else(|| failure(CLIENT_OUTPUT_INVALID))?;+ let identity = parse_qoder_output(&bytes, success).map_err(failure)?;let response_digest = CanonicalDigest::of_bytes(&bytes);self.verify_live_receipt(trust, &[identity], &response_digest, deadline)}@@ -145,31 +144,51 @@ impl LocalControlAdapter {}}-fn parse_qoder_output(bytes: &[u8]) -> Option<NativeAgentObservationIdentityV1> {+fn parse_qoder_output(+ bytes: &[u8],+ process_succeeded: bool,+) -> Result<NativeAgentObservationIdentityV1, &'static str> {+ let invalid = if process_succeeded {+ CLIENT_OUTPUT_INVALID+ } else {+ CLIENT_FAILED+ };let mut result = None;for line in bytes.split(|byte| *byte == b'\n').filter(|line| !line.iter().all(u8::is_ascii_whitespace)){- let value: serde_json::Value = serde_json::from_slice(line).ok()?;+ let value: serde_json::Value = serde_json::from_slice(line).map_err(|_| invalid)?;if value["type"] == "result" {- if result.is_some()- || value["subtype"] != "success"- || value["is_error"] != false- || value["result"].as_str()?.trim() != LIVE_PROMPT_RESPONSE- {- return None;- }- let session_id = value["session_id"].as_str()?;- if !valid_native_identity(session_id) {- return None;+ if result.is_some() || !value["subtype"].is_string() {+ return Err(invalid);}- result = Some(NativeAgentObservationIdentityV1::QoderSession {- session_id: session_id.into(),+ let message = value["result"].as_str().ok_or(invalid)?.trim();+ result = Some(if value["is_error"].as_bool().ok_or(invalid)? {+ // Qoder 1.1.65 reports this native prerequisite as a terminal error,+ // even with subtype=success and exit 0. Never expose its raw output.+ Err(if message == "Not logged in · Please run /login" {+ NATIVE_LOGIN_REQUIRED+ } else {+ CLIENT_FAILED+ })+ } else if !process_succeeded {+ Err(CLIENT_FAILED)+ } else {+ if value["subtype"] != "success" || message != LIVE_PROMPT_RESPONSE {+ return Err(invalid);+ }+ let session_id = value["session_id"].as_str().ok_or(invalid)?;+ if !valid_native_identity(session_id) {+ return Err(invalid);+ }+ Ok(NativeAgentObservationIdentityV1::QoderSession {+ session_id: session_id.into(),+ })});}}- result+ result.unwrap_or(Err(invalid))}#[cfg(test)]@@ -179,7 +198,7 @@ mod tests {fn qoder_live_requires_successful_terminal_marker_and_exact_native_identity() {let valid = br#"{"type":"result","subtype":"success","is_error":false,"result":"HIROUTE_LIVE_CHECK_OK","session_id":"native-session"}"#;assert!(- matches!(parse_qoder_output(valid),Some(NativeAgentObservationIdentityV1::QoderSession{session_id}) if session_id=="native-session")+ matches!(parse_qoder_output(valid, true),Ok(NativeAgentObservationIdentityV1::QoderSession{session_id}) if session_id=="native-session"));for changed in [String::from_utf8(valid.to_vec())@@ -194,7 +213,47 @@ mod tests {std::str::from_utf8(valid).unwrap()),] {- assert!(parse_qoder_output(changed.as_bytes()).is_none());+ assert!(parse_qoder_output(changed.as_bytes(), true).is_err());+ }+ assert_eq!(parse_qoder_output(valid, false).unwrap_err(), CLIENT_FAILED);+ }++ #[test]+ fn qoder_live_reports_native_login_failure_regardless_of_exit_status() {+ let native_failure = "{\"type\":\"result\",\"subtype\":\"success\",\"is_error\":true,\"result\":\"Not logged in · Please run /login\",\"duration_ms\":0,\"total_cost_usd\":0}";+ for process_succeeded in [true, false] {+ assert_eq!(+ parse_qoder_output(native_failure.as_bytes(), process_succeeded).unwrap_err(),+ NATIVE_LOGIN_REQUIRED+ );+ }+ let unknown_error =+ native_failure.replace("Not logged in · Please run /login", "Model unavailable");+ assert_eq!(+ parse_qoder_output(unknown_error.as_bytes(), true).unwrap_err(),+ CLIENT_FAILED+ );+ }++ #[test]+ fn qoder_live_does_not_infer_login_from_success_or_invalid_output() {+ let native_failure = "{\"type\":\"result\",\"subtype\":\"success\",\"is_error\":true,\"result\":\"Not logged in · Please run /login\"}";+ for invalid in [+ native_failure.replace("\"is_error\":true", "\"is_error\":false"),+ native_failure.replace("\"is_error\":true", "\"is_error\":\"true\""),+ native_failure.replace("\"subtype\":\"success\",", ""),+ format!("{native_failure}\n{native_failure}"),+ format!("{native_failure}\ninvalid json"),+ "Not logged in · Please run /login".into(),+ ] {+ assert_eq!(+ parse_qoder_output(invalid.as_bytes(), true).unwrap_err(),+ CLIENT_OUTPUT_INVALID+ );+ assert_eq!(+ parse_qoder_output(invalid.as_bytes(), false).unwrap_err(),+ CLIENT_FAILED+ );}}}