- 1
use std::path::Path; - 2
- 3
use crate::SandboxEventSink; - 4
- 5
/// Report a file produced by any built-in or delegated tool. The event uses a - 6
/// workspace-relative path so the client can resolve it through the same - 7
/// authenticated filesystem surface as every other result. - 8
pub fn emit_file(sink: Option<&SandboxEventSink>, path: &Path, cwd: &Path) { - 9
let Some(sink) = sink else { return }; - 10
let Ok(metadata) = path.metadata() else { - 11
return; - 12
}; - 13
if !metadata.is_file() { - 14
return; - 15
} - 16
let relative = path.strip_prefix(cwd).unwrap_or(path).display().to_string(); - 17
sink.emit_artifact(&relative, &guess_mime_type(path), metadata.len()); - 18
} - 19
- 20
pub fn guess_mime_type(path: &Path) -> String { - 21
let ext = path - 22
.extension() - 23
.and_then(|s| s.to_str()) - 24
.unwrap_or("") - 25
.to_ascii_lowercase(); - 26
match ext.as_str() { - 27
"png" => "image/png", - 28
"jpg" | "jpeg" => "image/jpeg", - 29
"gif" => "image/gif", - 30
"svg" => "image/svg+xml", - 31
"webp" => "image/webp", - 32
"html" | "htm" => "text/html", - 33
"css" => "text/css", - 34
"js" | "mjs" => "application/javascript", - 35
"json" => "application/json", - 36
"csv" => "text/csv", - 37
"tsv" => "text/tab-separated-values", - 38
"md" => "text/markdown", - 39
"txt" | "log" => "text/plain", - 40
"pdf" => "application/pdf", - 41
"zip" => "application/zip", - 42
"tar" => "application/x-tar", - 43
"gz" | "gzip" => "application/gzip", - 44
"doc" => "application/msword", - 45
"docx" => "application/vnd.openxmlformats-officedocument.wordprocessingml.document", - 46
"xls" => "application/vnd.ms-excel", - 47
"xlsx" => "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", - 48
"ppt" => "application/vnd.ms-powerpoint", - 49
"pptx" => "application/vnd.openxmlformats-officedocument.presentationml.presentation", - 50
"mp3" | "wav" | "ogg" | "m4a" | "aac" => "audio/*", - 51
"mp4" | "webm" | "mov" | "m4v" => "video/*", - 52
_ => "application/octet-stream", - 53
} - 54
.to_string() - 55
} - 56
Indexing the workspace…
Vakyartha documentation is discovering safe artifacts, anchors, and source references.