From 40a7f29d29c62e1eb00abd9db952e9ffbf6e760e Mon Sep 17 00:00:00 2001 From: Loong Date: Tue, 28 Jul 2026 12:22:45 +0100 Subject: [PATCH 1/4] feat: support new PRTS copilot URI format --- crates/maa-cli/src/run/preset/copilot.rs | 47 +++++++++++++++++++----- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/crates/maa-cli/src/run/preset/copilot.rs b/crates/maa-cli/src/run/preset/copilot.rs index 8f513750..a0e88654 100644 --- a/crates/maa-cli/src/run/preset/copilot.rs +++ b/crates/maa-cli/src/run/preset/copilot.rs @@ -376,15 +376,29 @@ enum CopilotFile { impl CopilotFile { fn from_uri(uri: &str) -> Result { let trimmed = uri.trim(); - if let Some(code_str) = trimmed.strip_prefix("maa://") { + let remote = if let Some(code_str) = trimmed.strip_prefix("prts://") { + if let Some(code_str) = code_str.strip_prefix('s') { + Some((code_str, true)) + } else { + Some((code_str, false)) + } + } else if let Some(code_str) = trimmed.strip_prefix("maa://") { + warn!("The maa:// URI format is deprecated; use prts:// or prts://s instead"); if let Some(code_str) = code_str.strip_suffix('s') { - Ok(CopilotFile::RemoteSet( - code_str.parse::().context("Invalid code")?, - )) + Some((code_str, true)) } else { - Ok(CopilotFile::Remote( - code_str.parse::().context("Invalid code")?, - )) + Some((code_str, false)) + } + } else { + None + }; + + if let Some((code_str, is_set)) = remote { + let code = code_str.parse::().context("Invalid code")?; + if is_set { + Ok(CopilotFile::RemoteSet(code)) + } else { + Ok(CopilotFile::Remote(code)) } } else if let Some(code) = trimmed.strip_prefix("file://") { Ok(CopilotFile::Local(PathBuf::from(code))) @@ -1484,23 +1498,36 @@ found"}"#, #[test] fn invalid_code() { - assert!(CopilotFile::from_uri("maa://xyz").is_err()); + assert!(CopilotFile::from_uri("prts://xyz").is_err()); + assert!(CopilotFile::from_uri("prts://s").is_err()); } #[test] fn remote_set() { assert_eq!( - CopilotFile::from_uri("maa://20001s").unwrap(), + CopilotFile::from_uri("prts://s20001").unwrap(), CopilotFile::RemoteSet(20001) ); } #[test] fn remote() { + assert_eq!( + CopilotFile::from_uri("prts://30001").unwrap(), + CopilotFile::Remote(30001) + ); + } + + #[test] + fn legacy_remote_remains_supported() { assert_eq!( CopilotFile::from_uri("maa://30001").unwrap(), CopilotFile::Remote(30001) ); + assert_eq!( + CopilotFile::from_uri("maa://20001s").unwrap(), + CopilotFile::RemoteSet(20001) + ); } #[test] @@ -1522,7 +1549,7 @@ found"}"#, #[test] fn with_whitespace() { assert_eq!( - CopilotFile::from_uri(" maa://30001 ").unwrap(), + CopilotFile::from_uri(" prts://30001 ").unwrap(), CopilotFile::Remote(30001) ); From f3ed3f254f3a96d5a21e7b99487c2bc324b905b8 Mon Sep 17 00:00:00 2001 From: Loong Date: Tue, 28 Jul 2026 20:45:48 +0100 Subject: [PATCH 2/4] fix: warn once for legacy copilot URIs --- crates/maa-cli/src/run/preset/copilot.rs | 55 +++++++++++++----------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/crates/maa-cli/src/run/preset/copilot.rs b/crates/maa-cli/src/run/preset/copilot.rs index a0e88654..59941b6d 100644 --- a/crates/maa-cli/src/run/preset/copilot.rs +++ b/crates/maa-cli/src/run/preset/copilot.rs @@ -1,6 +1,7 @@ use std::{ fs, path::{Path, PathBuf}, + sync::Once, }; use anyhow::{Context, Result, bail}; @@ -27,6 +28,8 @@ const COPILOT_API: &str = "http://127.0.0.1:18080/copilot/get/"; #[cfg(test)] const COPILOT_SET_API: &str = "http://127.0.0.1:18080/set/get?id="; +static LEGACY_URI_WARNING: Once = Once::new(); + /// Raid mode for copilot stages. #[cfg_attr(test, derive(Debug, PartialEq, Eq))] #[derive(Clone, Copy, Default, clap::ValueEnum)] @@ -374,37 +377,36 @@ enum CopilotFile { } impl CopilotFile { + fn parse_code(code: &str) -> Result { + code.parse::().context("Invalid code") + } + fn from_uri(uri: &str) -> Result { let trimmed = uri.trim(); - let remote = if let Some(code_str) = trimmed.strip_prefix("prts://") { - if let Some(code_str) = code_str.strip_prefix('s') { - Some((code_str, true)) - } else { - Some((code_str, false)) - } - } else if let Some(code_str) = trimmed.strip_prefix("maa://") { - warn!("The maa:// URI format is deprecated; use prts:// or prts://s instead"); - if let Some(code_str) = code_str.strip_suffix('s') { - Some((code_str, true)) - } else { - Some((code_str, false)) - } - } else { - None - }; - if let Some((code_str, is_set)) = remote { - let code = code_str.parse::().context("Invalid code")?; - if is_set { - Ok(CopilotFile::RemoteSet(code)) - } else { - Ok(CopilotFile::Remote(code)) + if let Some(code) = trimmed.strip_prefix("prts://s") { + return Ok(Self::RemoteSet(Self::parse_code(code)?)); + } + + if let Some(code) = trimmed.strip_prefix("prts://") { + return Ok(Self::Remote(Self::parse_code(code)?)); + } + + if let Some(code) = trimmed.strip_prefix("maa://") { + LEGACY_URI_WARNING.call_once(|| { + warn!( + "The maa:// URI format is deprecated; use prts:// or prts://s instead" + ); + }); + + if let Some(code) = code.strip_suffix('s') { + return Ok(Self::RemoteSet(Self::parse_code(code)?)); } - } else if let Some(code) = trimmed.strip_prefix("file://") { - Ok(CopilotFile::Local(PathBuf::from(code))) - } else { - Ok(CopilotFile::Local(PathBuf::from(trimmed))) + return Ok(Self::Remote(Self::parse_code(code)?)); } + + let path = trimmed.strip_prefix("file://").unwrap_or(trimmed); + Ok(Self::Local(PathBuf::from(path))) } pub fn push_path_into( @@ -1500,6 +1502,7 @@ found"}"#, fn invalid_code() { assert!(CopilotFile::from_uri("prts://xyz").is_err()); assert!(CopilotFile::from_uri("prts://s").is_err()); + assert!(CopilotFile::from_uri("maa://xyz").is_err()); } #[test] From 11ed9c1d776298bb0a1ff34890d18510ed1b4fab Mon Sep 17 00:00:00 2001 From: Loong Date: Wed, 19 Aug 2026 11:26:29 +0100 Subject: [PATCH 3/4] refactor: localize copilot URI parsing --- crates/maa-cli/src/run/preset/copilot.rs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/crates/maa-cli/src/run/preset/copilot.rs b/crates/maa-cli/src/run/preset/copilot.rs index 59941b6d..d3eeb525 100644 --- a/crates/maa-cli/src/run/preset/copilot.rs +++ b/crates/maa-cli/src/run/preset/copilot.rs @@ -377,19 +377,18 @@ enum CopilotFile { } impl CopilotFile { - fn parse_code(code: &str) -> Result { - code.parse::().context("Invalid code") - } - fn from_uri(uri: &str) -> Result { - let trimmed = uri.trim(); - - if let Some(code) = trimmed.strip_prefix("prts://s") { - return Ok(Self::RemoteSet(Self::parse_code(code)?)); + fn parse_code(code: &str) -> Result { + code.parse::().context("Invalid code") } + let trimmed = uri.trim(); + if let Some(code) = trimmed.strip_prefix("prts://") { - return Ok(Self::Remote(Self::parse_code(code)?)); + if let Some(code) = code.strip_prefix('s') { + return Ok(Self::RemoteSet(parse_code(code)?)); + } + return Ok(Self::Remote(parse_code(code)?)); } if let Some(code) = trimmed.strip_prefix("maa://") { @@ -400,9 +399,9 @@ impl CopilotFile { }); if let Some(code) = code.strip_suffix('s') { - return Ok(Self::RemoteSet(Self::parse_code(code)?)); + return Ok(Self::RemoteSet(parse_code(code)?)); } - return Ok(Self::Remote(Self::parse_code(code)?)); + return Ok(Self::Remote(parse_code(code)?)); } let path = trimmed.strip_prefix("file://").unwrap_or(trimmed); From 00b5ef54ade1997725ce1bd300a254c92dae7f5b Mon Sep 17 00:00:00 2001 From: Loong Date: Wed, 19 Aug 2026 11:48:30 +0100 Subject: [PATCH 4/4] refactor: simplify copilot URI branches --- crates/maa-cli/src/run/preset/copilot.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/crates/maa-cli/src/run/preset/copilot.rs b/crates/maa-cli/src/run/preset/copilot.rs index d3eeb525..b32a86eb 100644 --- a/crates/maa-cli/src/run/preset/copilot.rs +++ b/crates/maa-cli/src/run/preset/copilot.rs @@ -386,12 +386,11 @@ impl CopilotFile { if let Some(code) = trimmed.strip_prefix("prts://") { if let Some(code) = code.strip_prefix('s') { - return Ok(Self::RemoteSet(parse_code(code)?)); + Ok(Self::RemoteSet(parse_code(code)?)) + } else { + Ok(Self::Remote(parse_code(code)?)) } - return Ok(Self::Remote(parse_code(code)?)); - } - - if let Some(code) = trimmed.strip_prefix("maa://") { + } else if let Some(code) = trimmed.strip_prefix("maa://") { LEGACY_URI_WARNING.call_once(|| { warn!( "The maa:// URI format is deprecated; use prts:// or prts://s instead" @@ -399,13 +398,15 @@ impl CopilotFile { }); if let Some(code) = code.strip_suffix('s') { - return Ok(Self::RemoteSet(parse_code(code)?)); + Ok(Self::RemoteSet(parse_code(code)?)) + } else { + Ok(Self::Remote(parse_code(code)?)) } - return Ok(Self::Remote(parse_code(code)?)); + } else if let Some(path) = trimmed.strip_prefix("file://") { + Ok(Self::Local(PathBuf::from(path))) + } else { + Ok(Self::Local(PathBuf::from(trimmed))) } - - let path = trimmed.strip_prefix("file://").unwrap_or(trimmed); - Ok(Self::Local(PathBuf::from(path))) } pub fn push_path_into(