Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(review): capture the first visualization mutation

new-Beginner0914d312420a
diff --git a/crates/host-core/src/review.rs b/crates/host-core/src/review.rs
index 56e0425e0..1bcba3cc2 100644
--- a/crates/host-core/src/review.rs
+++ b/crates/host-core/src/review.rs
@@ -249,6 +249,14 @@ pub fn prepare_change(
let Some(input) = args.get("path").and_then(Value::as_str) else {
return Ok(None);
};
+ // Execution lazily creates a safe visualization root before resolving its
+ // target. Do the same after authorization so the first mutation is captured,
+ // not only later edits after that root already exists.
+ if let Some(claimed) = roots.lexical_root(input) {
+ if claimed.kind == ToolRoot::Visualization && claimed.allows_implicit_access() {
+ crate::visualizations::ensure_session_root(&claimed.path)?;
+ }
+ }
let Ok((resolved, root_kind)) =
workspace::resolve_tool_path_with_external(root, roots, input, allow_external_paths)
else {
diff --git a/crates/host-core/src/rpc/visualization_tests.rs b/crates/host-core/src/rpc/visualization_tests.rs
index 19cb5cc7b..2cf93a852 100644
--- a/crates/host-core/src/rpc/visualization_tests.rs
+++ b/crates/host-core/src/rpc/visualization_tests.rs
@@ -1,5 +1,5 @@
//! Session visualization root (D671): containment, `.html`-only writes,
-//! prompting, review exclusion, and lifecycle.
+//! prompting, non-reversible review evidence, and lifecycle.
use super::*;
use std::fs;
@@ -209,6 +209,7 @@ async fn rpc_redirected_visualization_write_prompts_and_denial_preserves_project
.await
.unwrap();
assert_eq!(pending.await.unwrap().unwrap()["errorCode"], "TOOL_DENIED");
+ assert!(!f.data_dir.join("review-changes").join(&id).exists());
assert_eq!(
fs::read_to_string(target.join("index.html")).unwrap(),
"important project file"
@@ -237,7 +238,13 @@ async fn rpc_direct_html_write_read_edit_user_path_uses_one_canonical_spelling()
.unwrap();
assert_eq!(write["ok"], true, "{write}");
assert_eq!(write["content"]["root"], "visualization");
- assert!(write["content"].get("review").is_none());
+ let written_review = &write["content"]["review"];
+ assert_eq!(written_review["operation"], "write");
+ assert_eq!(written_review["status"], "added");
+ assert_eq!(written_review["reversible"], false);
+ assert!(Path::new(written_review["path"].as_str().unwrap()).is_absolute());
+ assert_eq!(written_review["additions"], 1);
+ assert!(written_review["snapshotId"].as_str().is_some());
let read = handle_request(
state.clone(),
"tools.execute",
@@ -260,7 +267,14 @@ async fn rpc_direct_html_write_read_edit_user_path_uses_one_canonical_spelling()
).await.unwrap();
assert_eq!(edited["ok"], true, "{edited}");
assert_eq!(edited["content"]["root"], "visualization");
- assert!(edited["content"].get("review").is_none());
+ let edited_review = &edited["content"]["review"];
+ assert_eq!(edited_review["operation"], "edit");
+ assert_eq!(edited_review["status"], "modified");
+ assert_eq!(edited_review["reversible"], false);
+ assert_eq!(edited_review["path"], written_review["path"]);
+ assert_eq!(edited_review["additions"], 1);
+ assert_eq!(edited_review["deletions"], 1);
+ assert_ne!(edited_review["snapshotId"], written_review["snapshotId"]);
assert_eq!(fs::read_to_string(&path).unwrap(), "<p>after</p>");
while let Ok(note) = rx.try_recv() {
let note: Value = serde_json::from_str(&note).unwrap();
@@ -468,10 +482,40 @@ fn visualization_paths_do_not_require_external_path_permission() {
));
}
+#[test]
+fn review_preparation_leaves_unrelated_visualization_roots_lazy() {
+ let f = fixture();
+ let roots = local_contained_roots(&f.data_dir, "s1", false);
+ for (tool, path) in [
+ ("Read", f.visualization.join("chart.html")),
+ ("Bash", f.visualization.join("chart.html")),
+ ("Write", f.workspace.join("ordinary.txt")),
+ ] {
+ let pending = review::prepare_change(
+ &f.data_dir,
+ "s1",
+ "lazy-review",
+ Some(&f.workspace),
+ &roots,
+ tool,
+ &json!({"path":path}),
+ false,
+ )
+ .unwrap();
+ if let Some(pending) = pending {
+ review::discard_change(pending);
+ }
+ assert!(
+ !visualizations::base_dir(&f.data_dir).exists(),
+ "{tool} created an unrelated visualization root"
+ );
+ }
+}
+
#[test]
fn visualization_writes_are_reviewed_without_granting_rollback_access() {
let f = fixture();
- visualizations::ensure_session_root(&f.visualization).unwrap();
+ assert!(!f.visualization.exists());
let roots = local_contained_roots(&f.data_dir, "s1", false);
let pending = review::prepare_change(
&f.data_dir,
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index 75a291bbf..91fbbfa38 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -19429,6 +19429,11 @@ Scenario: E2E-REVIEW-ROUNDS (local desktop, implemented)
its diff remains readable after restart, its label is `.../basename`, and it
grants no rollback writes. Rust RPC tests cover workspace/scratch/external
Write and Edit, same-named paths, approval denial, failed Edit, and no Bash capture.
+ The visualization RPC Write → Read → Edit path starts with no visualization
+ directory and checks non-reversible review evidence for both mutations.
+ Ordinary operations keep that root lazy; denied redirected writes leave no
+ review snapshots. Run the complete visualization suite, not only review-named
+ tests, to cover the pre-existing cross-platform path contract.
`review-file-open.test.mjs` covers missing/fuzzy paths, worktree/secondary-root
locations, plugin unload, stale session/project results, and visible failures.
- Additional acceptance: Rust RPC tests cover over 100 turns/changes, dedup,