MCPcopy Create free account
hub / github.com/aws/amazon-q-developer-cli / pre_process

Function pre_process

crates/chat-cli/src/cli/chat/util/images.rs:42–57  ·  view source on GitHub ↗

Macos screenshots insert a NNBSP character rather than a space between the timestamp and AM/PM part. An example of a screenshot name is: /path-to/Screenshot 2025-03-13 at 1.46.32 PM.png However, the model will just treat it as a normal space and return the wrong path string to the `fs_read` tool. This will lead to file-not-found errors.

(path: &str)

Source from the content-addressed store, hash-verified

40/// However, the model will just treat it as a normal space and return the wrong path string to the
41/// `fs_read` tool. This will lead to file-not-found errors.
42pub fn pre_process(path: &str) -> String {
43 if cfg!(target_os = "macos") && path.contains("Screenshot") {
44 let mac_screenshot_regex =
45 regex::Regex::new(r"Screenshot \d{4}-\d{2}-\d{2} at \d{1,2}\.\d{2}\.\d{2} [AP]M").unwrap();
46 if mac_screenshot_regex.is_match(path) {
47 if let Some(pos) = path.find(" at ") {
48 let mut new_path = String::new();
49 new_path.push_str(&path[..pos + 4]);
50 new_path.push_str(&path[pos + 4..].replace(" ", "\u{202F}"));
51 return new_path;
52 }
53 }
54 }
55
56 path.to_string()
57}
58
59pub fn handle_images_from_paths(output: &mut impl Write, paths: &[String]) -> RichImageBlocks {
60 let mut extracted_images = Vec::new();

Callers 2

validateMethod · 0.85
invokeMethod · 0.85

Calls 1

to_stringMethod · 0.80

Tested by

no test coverage detected