Skip to content

Commit 93ca93b

Browse files
refactor(agents): reuse the LSP file-URI encoder in kiro
Kiro had a byte-duplicated `file_resource_uri` + `percent_encode_file_uri_path`. Widen the LSP client's `file_uri_from_path_text` to `pub(crate)` and have kiro delegate to it, deleting the private copies. POSIX paths encode identically to before; kiro now also gains the client's Windows drive-path and `//` UNC handling. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 0f3a399 commit 93ca93b

2 files changed

Lines changed: 8 additions & 26 deletions

File tree

src/agents/kiro.rs

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -336,32 +336,11 @@ fn mcp_server_entry(tracedecay_bin: &str) -> serde_json::Value {
336336
})
337337
}
338338

339+
/// Render a path as a `file://` resource URI for Kiro's agent config. Reuses
340+
/// the LSP client's encoder, which additionally handles Windows drive paths and
341+
/// UNC (`//server/share`) prefixes; POSIX paths encode identically to before.
339342
fn file_resource_uri(path: &Path) -> String {
340-
let path = path.to_string_lossy().replace('\\', "/");
341-
let path = percent_encode_file_uri_path(&path);
342-
if path.starts_with('/') {
343-
format!("file://{path}")
344-
} else {
345-
format!("file:///{path}")
346-
}
347-
}
348-
349-
fn percent_encode_file_uri_path(path: &str) -> String {
350-
const HEX: &[u8; 16] = b"0123456789ABCDEF";
351-
let mut encoded = String::with_capacity(path.len());
352-
for byte in path.bytes() {
353-
match byte {
354-
b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' | b'/' | b':' | b'-' | b'.' | b'_' | b'~' => {
355-
encoded.push(byte as char);
356-
}
357-
_ => {
358-
encoded.push('%');
359-
encoded.push(HEX[(byte >> 4) as usize] as char);
360-
encoded.push(HEX[(byte & 0x0F) as usize] as char);
361-
}
362-
}
363-
}
364-
encoded
343+
crate::diagnostics::lsp::client::file_uri_from_path_text(&path.to_string_lossy())
365344
}
366345

367346
fn managed_agent_config(

src/diagnostics/lsp/client.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,10 @@ fn file_uri(path: &Path) -> String {
524524
file_uri_from_path_text(&absolute.to_string_lossy())
525525
}
526526

527-
fn file_uri_from_path_text(path: &str) -> String {
527+
/// Build a `file://` URI from raw path text, normalizing `\` to `/` and
528+
/// percent-encoding. Handles POSIX paths, Windows drive paths (`C:/…`), and UNC
529+
/// (`//server/share`) prefixes. Shared with the Kiro installer.
530+
pub(crate) fn file_uri_from_path_text(path: &str) -> String {
528531
let normalized = path.replace('\\', "/");
529532
let encoded = percent_encode_file_uri_path(&normalized);
530533
if normalized.starts_with("//") {

0 commit comments

Comments
 (0)