feat: add static previews to the room pane

The preview tool could only name a port, so a static build needed a
server the terminal had to keep alive. `preview` now accepts a path:
the app reads the file or folder over the room's ssh sandbox and serves
it from a signed host, with `..` and dotfiles refused and a 16 MiB cap.

The target is stored with the room and replayed as a durable event. The
pane shows a static path with a reload control and keeps the port field
as a local fallback.
This commit is contained in:
vhaudiquet committed 2026-11-28 11:24:57 +01:00
1 parent 5be17cf4ef
commit 36de0aace7
20 files changed
+1046 -145

No files matched your search

+35
View File
@@ -42,6 +42,23 @@ pub fn member_color(index: usize) -> &'static str {
COLORS[index % COLORS.len()]
}
/// A workspace-relative path with no escape. Empty names the root.
pub fn safe_rel_path(path: &str) -> Result<String, String> {
let trimmed = path.trim();
if trimmed.starts_with('/') {
return Err("path must be relative to the workspace".into());
}
let normalized = trimmed.trim_matches('/');
if normalized.split('/').any(|part| part == "..") {
return Err("path escapes the workspace".into());
}
Ok(if normalized.is_empty() {
".".to_owned()
} else {
normalized.to_owned()
})
}
/// `@rhema` in any case, as a whole word.
pub fn mentions_agent(text: &str) -> bool {
let lower = text.to_lowercase();
@@ -67,6 +84,24 @@ pub fn mentions_agent(text: &str) -> bool {
mod tests {
use super::*;
#[test]
fn relative_paths_stay_under_the_workspace() {
assert_eq!(safe_rel_path("").unwrap(), ".");
assert_eq!(safe_rel_path("web/dist").unwrap(), "web/dist");
assert_eq!(
safe_rel_path("/web/dist/").unwrap_err(),
"path must be relative to the workspace"
);
assert_eq!(
safe_rel_path("web/../secret").unwrap_err(),
"path escapes the workspace"
);
assert_eq!(
safe_rel_path("..").unwrap_err(),
"path escapes the workspace"
);
}
#[test]
fn mentions_need_a_word_boundary() {
assert!(mentions_agent("@rhema fix this"));